如何知道我安装的 xdebug 版本?
问候
哈维
php -v
命令输出包括有关已安装 XDebug 版本的信息:
$ php -v
PHP 5.6.13-1+deb.sury.org~trusty+3 (cli)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans
或者
$ php -v | grep -i "xdebug"
你应该可以用一个简单的测试脚本来做到这一点:
<?php
phpinfo();
?>
并得到这样的输出:
在基于 Debian 的发行版(例如 Ubuntu)上:
aptitude show php5-xdebug | grep Version
在基于 Redhat 的发行版(例如 CentOS)上:
yum info php-pecl-xdebug | grep Version
我喜欢用
php -r "var_dump(phpversion('xdebug'));"
从命令行
在 PHP 中,使用phpversion
:
$version = phpversion('xdebug'); // "2.5.5"
Xdebug 使用 PHP 标准化的版本字符串格式,因此您可以version_compare
在其上使用:
if (version_compare('2.6.0.dev', $version, '<=')) {
echo 'You are running at least the development version 2.6.0 of Xdebug';
}
[仅供参考] 通过混合@daniel 和@bishop 的答案来检测xdebug 是否为v3。
php -r "exit(version_compare('3.0',phpversion('xdebug'),'>=')?1:0);"; echo $?
对于 Dockerfile 和/或 CI 中的 shell 脚本很有用。
#!/bin/sh
# bash compatible
if php -r "exit(version_compare('3.0',phpversion('xdebug'),'>=')?1:0);"; then
echo 'if xdebug3 then rewrite php.ini, downgrade, and etc.'
fi
我需要这个,因为在运行 PHPUnit 时出现以下错误。
Fatal error: Uncaught RuntimeException: Error #2: Use of undefined constant XDEBUG_CC_UNUSED - assumed 'XDEBUG_CC_UNUSED' (this will throw an Error in a future version of PHP) on line 56 in file /workspaces/Sample/vendor/phpunit/php-code-coverage/src/Driver/Xdebug.php in /workspaces/Sample/tests/TestCase.php on line 9