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.
This commit is contained in:
jfarrell 2015-08-25 01:09:35 -04:00
parent f13e431bab
commit 6949b7c969

View File

@ -397,7 +397,9 @@ void t_php_generator::init_generator() {
// 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 @@ void t_php_generator::generate_service(t_service* tservice) {
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;