问题描述
我正在使用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,"\"\"")
如果我下载7.2的src,则一切正常。我想我很惊讶,因为到目前为止我还没有编辑任何代码,所以我认为这等效于Hello World
系统,它似乎在版本之间具有最终的兼容性,因此不会除非我调用了已安装版本中不存在的函数,否则不会抛出错误。如果这是真的,并且正在调用7.2中没有的“新”函数,则似乎很奇怪,一个基本骨架将利用7.2中不存在的函数来显示“ Hello World”。
如果要在7.2中创建和编译,我以后是否可以在7.4中进行编译?如果我在7.4中进行编译,是否可以在7.2中使用它?
我要构建的扩展将具有非常简单的工作,但是需要快速且频繁地完成。诸如格式化电话号码,过滤json,处理递归树关系等等之类的事情。
已经看到了此兼容性问题,我很好奇这是否会使我锁定使用特定版本的PHP,即使我不尝试在代码中使用任何新功能时,仍然每次都必须重写它我们将在未来几年内升级PHP。
解决方法
特定PHP版本分支的框架可能会使用该版本中引入的功能/内部API,如果要构建与较低PHP版本兼容的扩展,则应使用该PHP版本的PHP扩展框架,而不是在来自最近的一个。