THRIFT-2981: IDL with no namespace produces unparsable PHP
Client: php
Patch: Randy Abernethy
The compiler is generating the namespace statement even when there isn't one, which blows up the PHP interpreter. Patch supresses service and type file output of namespace unless there actually is one.
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index 8919877..0026d70 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -397,7 +397,9 @@
// Print header
f_types_ << "<?php" << endl;
- f_types_ << "namespace " << php_namespace_suffix(get_program()) << ";" << endl << endl;
+ if ( ! php_namespace_suffix(get_program()).empty() ) {
+ f_types_ << "namespace " << php_namespace_suffix(get_program()) << ";" << endl << endl;
+ }
f_types_ << autogen_comment() << php_includes();
f_types_ << endl;
@@ -1143,7 +1145,9 @@
f_service_.open(f_service_name.c_str());
f_service_ << "<?php" << endl;
- f_service_ << "namespace " << php_namespace_suffix(tservice->get_program()) << ";" << endl;
+ if ( ! php_namespace_suffix(tservice->get_program()).empty() ) {
+ f_service_ << "namespace " << php_namespace_suffix(tservice->get_program()) << ";" << endl;
+ }
f_service_ << autogen_comment() << php_includes();
f_service_ << endl;