Home > Article > Backend Development > protocol-buffer - Problems encountered when upgrading protocolbuffers extension to php7?
Since protocolbuffers are being used in the project, the extensions used in the entire project basically support php7. Only protocolbuffers does not support php7. The original author has stopped maintaining the extension, and has no choice but to start researching how to extend protocolbuffers. Version 5.x is upgraded to php7. The extension currently compiles. 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>
The following is the test 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>
The output results are as follows:
<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>
Problem summary: When protocolbuffers::decode, the parsed object can be returned, but the properties of the object cannot be read. Solving. . .
Since protocolbuffers are being used in the project, the extensions used in the entire project basically support php7. Only protocolbuffers does not support php7. The original author has stopped maintaining the extension, and has no choice but to start researching how to extend protocolbuffers. Version 5.x is upgraded to php7. The extension currently compiles. 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>
The following is the test 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>
The output results are as follows:
<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>
Problem summary: When protocolbuffers::decode, the parsed object can be returned, but the properties of the object cannot be read. Solving. . .