Make sure to lazily initialize $TSPEC for structs even with no members
authorMark Slee <mcslee@apache.org>
Fri, 16 Nov 2007 03:27:22 +0000 (03:27 +0000)
committerMark Slee <mcslee@apache.org>
Fri, 16 Nov 2007 03:27:22 +0000 (03:27 +0000)
Reviewed By: dweatherford

Test Plan: Generate code with no E_ALL for method-less args

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665346 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_php_generator.cc

index c16cfa4..c0fdd25 100644 (file)
@@ -398,28 +398,27 @@ void t_php_generator::generate_php_struct_definition(ofstream& out,
   out << endl;
 
   // Generate constructor from array
-  if (members.size() > 0) {
-    out <<
-      indent() << "public function __construct($vals=null) {" << endl;
-    indent_up();
+  string param = (members.size() > 0) ? "$vals=null" : "";
+  out <<
+    indent() << "public function __construct(" << param << ") {" << endl;
+  indent_up();
 
-    generate_php_struct_spec(out, tstruct);
+  generate_php_struct_spec(out, tstruct);
 
+  if (members.size() > 0) {
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
       t_type* t = get_true_type((*m_iter)->get_type());
       if ((*m_iter)->get_value() != NULL && (t->is_struct() || t->is_xception())) {
         indent(out) << "$this->" << (*m_iter)->get_name() << " = " << render_const_value(t, (*m_iter)->get_value()) << ";" << endl;
       }
     }
-
     out <<
       indent() << "if (is_array($vals)) {" << endl <<
       indent() << "  parent::__construct(self::$_TSPEC, $vals);" << endl <<
       indent() << "}" << endl;
-    scope_down(out);
-
-    out << endl;
   }
+  scope_down(out);
+  out << endl;
 
   out <<
     indent() << "public function getName() {" << endl <<