运行以下命令:
foreach(get_loaded_extensions() as $name){
$extensions[strtolower($name)] = phpversion($name);
}
var_dump($extensions);
我注意到一些加载的扩展没有显示版本,而是显示为 false,例如:
'pcre' => boolean false
但是,当我点击 phpinfo()
时,它显示了一个版本号:
为什么 phpversion()
函数没有获取正确的结果?我知道在这种情况下我可以简单地拉取 PCRE_VERSION
,但是需要对一些但不是所有的扩展这样做是愚蠢的; gd
也显示 false。
编辑:修复;
foreach(get_loaded_extensions() as $name){
$extensions[strtolower($name)] = phpversion($name);
}
$extensions = array_replace($extensions, array(
'iconv' => ICONV_VERSION,
'pcre' => PCRE_VERSION,
'libxml' => LIBXML_DOTTED_VERSION,
'gd' => GD_VERSION,
// others i may be missing, will get to it
));
编辑:这是完整的转储和 phpinfo()
输出,只是为了笑笑:
array
'core' => string '5.3.8' (length=5)
'bcmath' => boolean false
'calendar' => boolean false
'com_dotnet' => string '0.1' (length=3)
'ctype' => boolean false
'date' => string '5.3.8' (length=5)
'ereg' => boolean false
'filter' => string '0.11.0' (length=6)
'ftp' => boolean false
'hash' => string '1.0' (length=3)
'iconv' => boolean false
'json' => string '1.2.1' (length=5)
'mcrypt' => boolean false
'spl' => string '0.2' (length=3)
'odbc' => string '1.0' (length=3)
'pcre' => boolean false
'reflection' => string '$Revision: 313665 $' (length=19)
'session' => boolean false
'standard' => string '5.3.8' (length=5)
'mysqlnd' => string 'mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $' (length=50)
'tokenizer' => string '0.1' (length=3)
'zip' => string '1.9.1' (length=5)
'zlib' => string '1.1' (length=3)
'libxml' => boolean false
'dom' => string '20031129' (length=8)
'pdo' => string '1.0.4dev' (length=8)
'bz2' => boolean false
'simplexml' => string '0.1' (length=3)
'wddx' => boolean false
'xml' => boolean false
'xmlreader' => string '0.1' (length=3)
'xmlwriter' => string '0.1' (length=3)
'apache2handler' => boolean false
'phar' => string '2.0.1' (length=5)
'mbstring' => boolean false
'exif' => string '1.4 $Id: exif.c 314376 2011-08-06 14:47:44Z felipe $' (length=52)
'gd' => boolean false
'gettext' => boolean false
'imap' => boolean false
'mysql' => string '1.0' (length=3)
'mysqli' => string '0.1' (length=3)
'pdo_mysql' => string '1.0.2' (length=5)
'pdo_odbc' => string '1.0.1' (length=5)
'pdo_sqlite' => string '1.0.1' (length=5)
'soap' => boolean false
'sockets' => boolean false
'sqlite' => string '2.0-dev' (length=7)
'sqlite3' => string '0.7-dev' (length=7)
'tidy' => string '2.0' (length=3)
'xmlrpc' => string '0.51' (length=4)
'mhash' => boolean false
'xdebug' => string '2.1.1' (length=5)
最佳答案
phpversion() returns the version of that extension, or FALSE if there is no version information associated or the extension isn't enabled.
你在phpinfo()
中看到的不是扩展的版本信息,而是库的c-client版本。 prce
扩展本身没有版本信息。
关于PHP扩展版本不一致;更可靠的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7949615/