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.
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 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 @@
}
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 @@
}
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 @@
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 86fff40..380ff10 100644
--- a/lib/php/lib/Thrift/Protocol/TProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TProtocol.php
@@ -29,12 +29,6 @@
* 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