Skip to content

Commit befb835

Browse files
authored
PHPC-2275: Always consult php-config for PHP version check in config.m4 (#1477)
Typically, PHP_VERSION and PHP_VERSION_ID are only defined when building the extension statically with PHP, since those variables are defined in php-src's own configure.ac. The variables are not defined when using phpize for a shared build. The PHP Docker images for Alpine happen to define PHP_VERSION in their shell, but not PHP_VERSION_ID, which resulted in an "sh: out of range" error attempting to check the version. The shell-defined PHP_VERSION is also not necessarily the value we'd get from php-config (edge case where someone installs a different PHP version on top of an existing image). This changes the logic to always rely on php-config to derive these values, as is done in various other extensions (e.g. xdebug, parallel). The awk one-liner that calculates PHP_VERSION_ID is also replaced with a direct call to `php-config --vernum`, which has been available since PHP 5.4 (php/php-src@f0fe4e0).
1 parent 4177e66 commit befb835

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

config.m4

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ if test "$PHP_MONGODB" != "no"; then
1616
dnl Check PHP version is compatible with this extension
1717
AC_MSG_CHECKING([PHP version])
1818

19-
PHP_MONGODB_PHP_VERSION=$PHP_VERSION
20-
PHP_MONGODB_PHP_VERSION_ID=$PHP_VERSION_ID
21-
22-
if test -z "$PHP_MONGODB_PHP_VERSION"; then
23-
if test -z "$PHP_CONFIG"; then
24-
AC_MSG_ERROR([php-config not found])
25-
fi
26-
PHP_MONGODB_PHP_VERSION=`${PHP_CONFIG} --version`
27-
PHP_MONGODB_PHP_VERSION_ID=`echo "${PHP_MONGODB_PHP_VERSION}" | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 100 + [$]2) * 100 + [$]3;}'`
19+
if test -z "$PHP_CONFIG"; then
20+
AC_MSG_ERROR([php-config not found])
2821
fi
2922

23+
PHP_MONGODB_PHP_VERSION=`${PHP_CONFIG} --version`
24+
PHP_MONGODB_PHP_VERSION_ID=`${PHP_CONFIG} --vernum`
25+
3026
AC_MSG_RESULT($PHP_MONGODB_PHP_VERSION)
27+
3128
if test "$PHP_MONGODB_PHP_VERSION_ID" -lt "70400"; then
3229
AC_MSG_ERROR([not supported. Need a PHP version >= 7.4.0 (found $PHP_MONGODB_PHP_VERSION)])
3330
fi

0 commit comments

Comments
 (0)