Thrift-1903: PHP namespaces cause binary protocols to not be used
authorJake Farrell <jfarrell@apache.org>
Sat, 20 Apr 2013 01:58:33 +0000 (21:58 -0400)
committerJake Farrell <jfarrell@apache.org>
Sat, 20 Apr 2013 01:58:33 +0000 (21:58 -0400)
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.

compiler/cpp/src/generate/t_php_generator.cc
lib/php/lib/Thrift/Protocol/TProtocol.php

index ef8185d..833caef 100644 (file)
@@ -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_ <<
index 86fff40..380ff10 100644 (file)
@@ -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