编程语言
首页 > 编程语言> > PHP扩展版本不一致;更可靠的方法?

PHP扩展版本不一致;更可靠的方法?

作者:互联网

运行以下命令:

foreach(get_loaded_extensions() as $name){
    $extensions[strtolower($name)] = phpversion($name);
}
var_dump($extensions);

我注意到某些已加载的扩展名未显示版本,例如,具有false:

'pcre' => boolean false

但是,当我点击phpinfo()时,它显示了一个版本号:

为什么phpversion()函数无法获取正确的结果?我知道在这种情况下,我可以简单地拉PCRE_VERSION,但是需要对某些但并非所有扩展都这样做是很愚蠢的. gd也显示假.

编辑:修复;

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客户端版本. prce扩展本身没有版本信息.

标签:php-extension,versioning,php
来源: https://codeday.me/bug/20191202/2086319.html