You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2013/04/20 04:02:43 UTC

git commit: Thrift-1903: PHP namespaces cause binary protocols to not be used Client: php Patch: Tyler Hobbs

Updated Branches:
  refs/heads/master 1bd9424b4 -> de262dc77


Thrift-1903: PHP namespaces cause binary protocols to not be used
Client: php
Patch: Tyler Hobbs

Resolves the issue by importing TBinaryProtocolAccelerated and checking if $this->output_ is an instance of that instead of using a static string in TProtocol.


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/de262dc7
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/de262dc7
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/de262dc7

Branch: refs/heads/master
Commit: de262dc77ee06ab40859230dd57f383ac4f32c61
Parents: 1bd9424
Author: Jake Farrell <jf...@apache.org>
Authored: Fri Apr 19 21:58:33 2013 -0400
Committer: Jake Farrell <jf...@apache.org>
Committed: Fri Apr 19 21:58:33 2013 -0400

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_php_generator.cc |    9 +++++----
 lib/php/lib/Thrift/Protocol/TProtocol.php    |    6 ------
 2 files changed, 5 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/de262dc7/compiler/cpp/src/generate/t_php_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index ef8185d..833caef 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -403,9 +403,10 @@ string t_php_generator::php_includes() {
   string TException = "use Thrift\\Exception\\TException;\n";
   string TProtocolException = "use Thrift\\Exception\\TProtocolException;\n";
   string TProtocol = "use Thrift\\Protocol\\TProtocol;\n";
+  string TBinaryProtocolAccelerated = "use Thrift\\Protocol\\TBinaryProtocolAccelerated;\n";
   string TApplicationException = "use Thrift\\Exception\\TApplicationException;\n\n";
 
-  return TBase + TType + TMessageType + TException + TProtocolException + TProtocol + TApplicationException;
+  return TBase + TType + TMessageType + TException + TProtocolException + TProtocol + TBinaryProtocolAccelerated + TApplicationException;
 }
 
 /**
@@ -1205,7 +1206,7 @@ void t_php_generator::generate_process_function(t_service* tservice,
   }
 
   f_service_ <<
-    indent() << "$bin_accel = ($output instanceof " << "TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary');" << endl;
+    indent() << "$bin_accel = ($output instanceof " << "TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');" << endl;
 
   f_service_ <<
     indent() << "if ($bin_accel)" << endl;
@@ -1486,7 +1487,7 @@ void t_php_generator::generate_service_client(t_service* tservice) {
       }
 
       f_service_ <<
-        indent() << "$bin_accel = ($this->output_ instanceof " << "TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary');" << endl;
+        indent() << "$bin_accel = ($this->output_ instanceof " << "TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');" << endl;
 
       f_service_ <<
         indent() << "if ($bin_accel)" << endl;
@@ -1544,7 +1545,7 @@ void t_php_generator::generate_service_client(t_service* tservice) {
       scope_up(f_service_);
 
       f_service_ <<
-        indent() << "$bin_accel = ($this->input_ instanceof " << "TProtocol::$TBINARYPROTOCOLACCELERATED)"
+        indent() << "$bin_accel = ($this->input_ instanceof " << "TBinaryProtocolAccelerated)"
                  << " && function_exists('thrift_protocol_read_binary');" << endl;
 
       f_service_ <<

http://git-wip-us.apache.org/repos/asf/thrift/blob/de262dc7/lib/php/lib/Thrift/Protocol/TProtocol.php
----------------------------------------------------------------------
diff --git a/lib/php/lib/Thrift/Protocol/TProtocol.php b/lib/php/lib/Thrift/Protocol/TProtocol.php
index 86fff40..380ff10 100644
--- a/lib/php/lib/Thrift/Protocol/TProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TProtocol.php
@@ -29,12 +29,6 @@ use Thrift\Exception\TProtocolException;
  * Protocol base class module.
  */
 abstract class TProtocol {
-  // The below may seem silly, but it is to get around the problem that the
-  // "instanceof" operator can only take in a T_VARIABLE and not a T_STRING
-  // or T_CONSTANT_ENCAPSED_STRING. Using "is_a()" instead of "instanceof" is
-  // a workaround but is deprecated in PHP5. This is used in the generated
-  // deserialization code.
-  static $TBINARYPROTOCOLACCELERATED = 'TBinaryProtocolAccelerated';
 
   /**
    * Underlying transport