Do not generate constants php files from Thrift when they will be empty

Summary: That's just silly

Reviewed By: peter, dreiss

Test Plan: Generate PHP from a .thrift with no constants. Notice there is no _constants.php generated.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665355 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index 8a3bdb7..9cf98ae 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -23,8 +23,6 @@
   // Make output file
   string f_types_name = get_out_dir()+program_name_+"_types.php";
   f_types_.open(f_types_name.c_str());
-  string f_consts_name = get_out_dir()+program_name_+"_constants.php";
-  f_consts_.open(f_consts_name.c_str());
 
   // Print header
   f_types_ <<
@@ -42,13 +40,17 @@
   f_types_ << endl;
 
   // Print header
-  f_consts_ <<
-    "<?php" << endl <<
-    autogen_comment() <<
-    "include_once $GLOBALS['THRIFT_ROOT'].'/packages/" + program_name_ + "/" + program_name_ + "_types.php';" << endl <<
-    endl <<
-    "$GLOBALS['" << program_name_ << "_CONSTANTS'] = array(); " << endl <<
-    endl;
+  if (!program_->get_consts().empty()) {
+    string f_consts_name = get_out_dir()+program_name_+"_constants.php";
+    f_consts_.open(f_consts_name.c_str());
+    f_consts_ <<
+      "<?php" << endl <<
+      autogen_comment() <<
+      "include_once $GLOBALS['THRIFT_ROOT'].'/packages/" + program_name_ + "/" + program_name_ + "_types.php';" << endl <<
+      endl <<
+      "$GLOBALS['" << program_name_ << "_CONSTANTS'] = array(); " << endl <<
+      endl;
+  }
 }
 
 /**
@@ -67,8 +69,10 @@
   f_types_ << "?>" << endl;
   f_types_.close();
 
-  f_consts_ << "?>" << endl;
-  f_consts_.close();
+  if (!program_->get_consts().empty()) {
+    f_consts_ << "?>" << endl;
+    f_consts_.close();
+  }
 }
 
 /**