【发布时间】: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