Maison >développement back-end >tutoriel php >protocol-buffer - protocolbuffers扩展升级到php7遇到的问题?
由于项目中正在使用protocolbuffers,整个项目中使用到的扩展基本都已经支持php7,只有protocolbuffers这个还不支持php7,原作者已经停止维护了该扩展,无奈只能自己开始研究如何将protocolbuffers扩展的5.x版本升级到php7。目前该扩展可以通过编译。github
<code>Number of tests : 144 144 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 67 ( 46.5%) ( 46.5%) Expected fail : 0 ( 0.0%) ( 0.0%) Tests passed : 77 ( 53.5%) ( 53.5%)</code>
以下为测试代码:
<code><?php require dirname(__FILE__) . DIRECTORY_SEPARATOR . "messages" . DIRECTORY_SEPARATOR . "field_int32.proto.php"; $bytes = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "fixtures" . DIRECTORY_SEPARATOR . "001_int32_init.bin"); $u = new Tutorial_Integer32(); $u->setValue(0); $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); var_dump($obj); if ($obj instanceof Tutorial_Integer32) { var_dump($obj->getValue()); if ($obj->getValue() == 0) { echo "OK" . PHP_EOL; } else { var_dump($obj); } } else { var_dump($obj); } ini_set("protocolbuffers.native_scalars", 1); $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); if ($obj instanceof Tutorial_Integer32) { var_dump($obj->getValue()); if ($obj->getValue() === 0) { echo "OK" . PHP_EOL; } else { var_dump($obj); } } else { var_dump($obj); } </code>
输出结果如下:
<code>object(Tutorial_Integer32)#2 (2) { ["_properties":protected]=> array(0) { } ["value":protected]=> string(1) "0" } NULL OK NULL object(Tutorial_Integer32)#3 (2) { ["_properties":protected]=> array(0) { } ["value":protected]=> int(0) }</code>
问题总结:在protocolbuffers::decode时,能够返回被解析的对象,但是对象的属性无法读取。求解中。。。
由于项目中正在使用protocolbuffers,整个项目中使用到的扩展基本都已经支持php7,只有protocolbuffers这个还不支持php7,原作者已经停止维护了该扩展,无奈只能自己开始研究如何将protocolbuffers扩展的5.x版本升级到php7。目前该扩展可以通过编译。github
<code>Number of tests : 144 144 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 67 ( 46.5%) ( 46.5%) Expected fail : 0 ( 0.0%) ( 0.0%) Tests passed : 77 ( 53.5%) ( 53.5%)</code>
以下为测试代码:
<code><?php require dirname(__FILE__) . DIRECTORY_SEPARATOR . "messages" . DIRECTORY_SEPARATOR . "field_int32.proto.php"; $bytes = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "fixtures" . DIRECTORY_SEPARATOR . "001_int32_init.bin"); $u = new Tutorial_Integer32(); $u->setValue(0); $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); var_dump($obj); if ($obj instanceof Tutorial_Integer32) { var_dump($obj->getValue()); if ($obj->getValue() == 0) { echo "OK" . PHP_EOL; } else { var_dump($obj); } } else { var_dump($obj); } ini_set("protocolbuffers.native_scalars", 1); $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); if ($obj instanceof Tutorial_Integer32) { var_dump($obj->getValue()); if ($obj->getValue() === 0) { echo "OK" . PHP_EOL; } else { var_dump($obj); } } else { var_dump($obj); } </code>
输出结果如下:
<code>object(Tutorial_Integer32)#2 (2) { ["_properties":protected]=> array(0) { } ["value":protected]=> string(1) "0" } NULL OK NULL object(Tutorial_Integer32)#3 (2) { ["_properties":protected]=> array(0) { } ["value":protected]=> int(0) }</code>
问题总结:在protocolbuffers::decode时,能够返回被解析的对象,但是对象的属性无法读取。求解中。。。