[ https://issues.apache.org/jira/browse/THRIFT-1903?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13637105#comment-13637105 ]
Sean Fannan commented on THRIFT-1903: ------------------------------------- I built the new thrift with this new patch and we are getting this error. Think it's related to this or to something else? PHP Fatal error: Class 'TProtocolException' not found in XXXX > PHP namespaces cause binary protocols to not be used > ---------------------------------------------------- > > Key: THRIFT-1903 > URL: https://issues.apache.org/jira/browse/THRIFT-1903 > Project: Thrift > Issue Type: Bug > Components: PHP - Compiler, PHP - Library > Affects Versions: 0.9 > Environment: Centos 6.4 > Reporter: Tim Behrendsen > Assignee: Tyler Hobbs > Fix For: 1.0 > > Attachments: THRIFT-1903-v1.txt > > > Currently the compiled code produces the following check for binary > capability (slightly different in other places, but same idea): > {noformat} > $bin_accel = ($this->output_ instanceof > TProtocol::$TBINARYPROTOCOLACCELERATED) && > function_exists('thrift_protocol_write_binary'); > {noformat} > The TProtocol::$TBINARYPROTOCOLACCELERATED variable contains > 'TBinaryProtocolAccelerated'. This check always fails because when the > protocol class is instantiated like: > {noformat} > use Thrift\Protocol\TBinaryProtocolAccelerated; > $protocol = new TBinaryProtocolAccelerated($transport); > {noformat} > (as shown in the current PHP example), the protocol class is instantiated as > 'Thrift\Protocol\TBinaryProtocolAccelerated'. In the standard compiled class, > TBinaryProtocolAccelerated's namespace is not use'd, so the instanceof fails. > EXAMPLE PROGRAM > Based on PHP tutorial, only needs compiled code. Does not make a > connection and demonstrates the instanceof failure. > -------------------------------------------------------------------- > {noformat} > namespace tutorial\php; > define('THRIFT_ROOT', '/home/tim/projects/inquisic/thrift-0.9.0/lib/php/lib'); > require_once(THRIFT_ROOT . '/Thrift/ClassLoader/ThriftClassLoader.php'); > use Thrift\ClassLoader\ThriftClassLoader; > $GEN_DIR = '/home/tim/public_html/thrift0.9/gen-php'; > $loader = new ThriftClassLoader(); > $loader->registerNamespace('Thrift', THRIFT_ROOT); > $loader->registerDefinition('shared', $GEN_DIR); > $loader->registerDefinition('tutorial', $GEN_DIR); > $loader->register(); > use Thrift\Protocol\TBinaryProtocol; > use Thrift\Protocol\TBinaryProtocolAccelerated; > use Thrift\Transport\THttpClient; > use Thrift\Transport\TBufferedTransport; > $socket = new THttpClient('localhost', 8383, '/~tim/thrift0.9/PhpServer.php'); > $transport = new TBufferedTransport($socket, 1024, 1024); > $protocol = new TBinaryProtocolAccelerated($transport); > // Reset namespace > namespace tutorial\php; > use Thrift\Protocol\TProtocol; > use Thrift\Protocol\TBinaryProtocol; > print "protocol class = " . get_class($protocol) . "\n"; > print "check class = " . TProtocol::$TBINARYPROTOCOLACCELERATED . "\n"; > if ($protocol instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) > print "Standard: INSTANCE!\n"; > else > print "Standard: NOT INSTANCE!\n"; > $good_class = '\Thrift\Protocol\TBinaryProtocolAccelerated'; > if ($protocol instanceof $good_class) > print "Good: INSTANCE!\n"; > else > print "Good: NOT INSTANCE!\n"; > {noformat} > --------------------------------------------------------------------- > PROGRAM OUTPUT: > --------------------------------------------------------------------- > {noformat} > protocol class = Thrift\Protocol\TBinaryProtocolAccelerated > check class = TBinaryProtocolAccelerated > Standard: NOT INSTANCE! > Good: INSTANCE! > {noformat} > --------------------------------------------------------------------- > WORKAROUND: > Note that leading backslash is required. Just having 'Thrift\Protocol\...' > etc will not work. > --------------------------------------------------------------------- > {noformat} > Changed line 37 in TProtocol.php to: > static $TBINARYPROTOCOLACCELERATED = > '\Thrift\Protocol\TBinaryProtocolAccelerated'; > {noformat} > --------------------------------------------------------------------- -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira