【问题标题】:Custom PHP Extension Cross Compatibility自定义 PHP 扩展交叉兼容性
【发布时间】:2020-10-01 20:41:41
【问题描述】:

我正在使用https://www.zend.com/resources/writing-php-extensions 作为路线图构建我的第一个 PHP 扩展,并遇到了一些(对我而言)有趣的问题。

服务器上安装的是 PHP 7.2,但当前的master 版本是 7.4。我将php-src-master复制到服务器上并执行php ext_skel.php --ext test --dir 的第一步,然后

# phpize
# ./configure
# make

然后我得到这个错误:

/bin/bash /root/php-src-master/ext/test/libtool --mode=compile cc  -I. -I/root/php-src-master/ext/test -DPHP_ATOM_INC -I/root/php-src-master/ext/test/include -I/root/php-src-master/ext/test/main -I/root/php-src-master/ext/test -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /root/php-src-master/ext/test/test.c -o test.lo 
libtool: compile:  cc -I. -I/root/php-src-master/ext/test -DPHP_ATOM_INC -I/root/php-src-master/ext/test/include -I/root/php-src-master/ext/test/main -I/root/php-src-master/ext/test -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-src-master/ext/test/test.c  -fPIC -DPIC -o .libs/test.o
In file included from /root/php-src-master/ext/test/test.c:10:0:

/root/php-src-master/ext/test/test_arginfo.h:8:2: warning: implicit declaration of function ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE [-Wimplicit-function-declaration]
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, str, IS_STRING, 0, "\"\"")

如果我下载 7.2 的 src,那么一切正常。我想我很惊讶,因为此时我根本没有编辑任何代码,所以我认为这相当于Hello World 系统,它似乎在版本之间具有终极兼容性,因此不会抛出除非我调用已安​​装版本中不存在的函数,否则会出错。如果这是真的,并且正在调用 7.2 中不存在的“新”函数,那么基本骨架会利用 7.2 中不存在的函数来显示“Hello World”似乎很奇怪。

如果我在 7.2 中创建和编译,我以后可以在 7.4 中编译吗?如果我在 7.4 中编译,我可以在 7.2 中使用它吗?

我想要构建的扩展将有非常简单的工作,但需要快速且频繁地完成。诸如格式化电话号码、过滤 json、处理递归树关系等等。

看到这个兼容性问题,我很好奇这是否会让我无法使用特定版本的 PHP,即使我没有尝试在我的代码中使用任何新函数,我仍然必须每次都重写它我们会在未来几年升级 PHP。

【问题讨论】:

  • implicit-function-declaration 表示在链接时找不到函数。您可能需要-l-L 来告诉链接器在哪里可以找到它。

标签: php php-extension


【解决方案1】:

特定 PHP 版本分支的框架可以使用该版本中引入的功能/内部 API,如果您想构建与较低 PHP 版本兼容的扩展,您应该使用该 PHP 版本的 PHP 扩展框架,而不是在来自最近的一个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 2011-12-31
    • 1970-01-01
    相关资源
    最近更新 更多