protocol-buffer - protocolbuffers扩展升级到php7遇到的问题?
背景
由于项目中正在使用protocolbuffers,整个项目中使用到的扩展基本都已经支持php7,只有protocolbuffers这个还不支持php7,原作者已经停止维护了该扩展,无奈只能自己开始研究如何将protocolbuffers扩展的5.x版本升级到php7。目前该扩展可以通过编译。github
make test结果如下:
<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
make test结果如下:
<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时,能够返回被解析的对象,但是对象的属性无法读取。求解中。。。

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu
