From de262dc77ee06ab40859230dd57f383ac4f32c61 Mon Sep 17 00:00:00 2001 From: Jake Farrell Date: Fri, 19 Apr 2013 21:58:33 -0400 Subject: [PATCH] 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. --- compiler/cpp/src/generate/t_php_generator.cc | 9 +++++---- lib/php/lib/Thrift/Protocol/TProtocol.php | 6 ------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc index ef8185dc..833caefa 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_ << diff --git a/lib/php/lib/Thrift/Protocol/TProtocol.php b/lib/php/lib/Thrift/Protocol/TProtocol.php index 86fff404..380ff10e 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 -- 2.17.1