34

如何知道我安装的 xdebug 版本?

问候

哈维

4

6 回答 6

46

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"
于 2015-09-19T12:47:33.427 回答
16

你应该可以用一个简单的测试脚本来做到这一点:

<?php
  phpinfo();
?>

并得到这样的输出:

phpinfo输出截图

于 2010-03-19T18:41:27.323 回答
11

在基于 Debian 的发行版(例如 Ubuntu)上:

aptitude show php5-xdebug | grep Version

在基于 Redhat 的发行版(例如 CentOS)上:

yum info php-pecl-xdebug | grep Version
于 2012-05-13T20:26:10.313 回答
7

我喜欢用

php -r "var_dump(phpversion('xdebug'));"

从命令行

于 2020-07-16T18:54:24.367 回答
5

在 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';
}
于 2017-12-29T17:16:59.740 回答
2

[仅供参考] 通过混合@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
于 2020-12-04T01:28:19.500 回答