3

Having run the following:

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

I notice that some of the loaded extensions don't show a version, having false instead, for instance:

'pcre' => boolean false

However, when I hit up phpinfo(), it shows a version number: enter image description here

Why isn't the phpversion() function fetching the correct results? I understand in this instance I could simply pull PCRE_VERSION, but needing to do so for some but not all extensions is silly; gd shows false too.


Edit: Fix;

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
));

Edit: Here's the full dump and the phpinfo() output, just for giggles:

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)

enter image description here

Dan Lugg
  • 20,192
  • 19
  • 110
  • 174
  • Isn't there a version of the shared library installed in the system, not the extension itself? – zerkms Oct 31 '11 at 03:07
  • That's weird. http://lxr.php.net/opengrok/xref/PHP_5_3/ext/standard/info.c#92 prints the `zend_module->version` and then phpversion http://lxr.php.net/opengrok/xref/PHP_5_3/ext/standard/info.c#1263 calls http://lxr.php.net/opengrok/xref/PHP_5_3/Zend/zend_API.c#3077 which also returns the `module->version`. I am curious too. – chx Oct 31 '11 at 03:21
  • Is your PCRE statically linked in to PHP, or loaded dynamically? I suspect it isn't actually a loaded extension when it's compiled in. – Phil Lello Oct 31 '11 at 03:37
  • @Phil Lello - Ah, good point, perhaps that's why. I suppose I should accommodate for such circumstances in a dump, as with `gd` and others. – Dan Lugg Oct 31 '11 at 03:40

1 Answers1

3

phpversion() returns the version of that extension, or FALSE if there is no version information associated or the extension isn't enabled.

What you saw in phpinfo() is not the version information of the extension but the c-client version of the library. The prce extension itself has no version information.

xdazz
  • 158,678
  • 38
  • 247
  • 274
  • Thanks @xdazz - I'll resort to checking certain extensions (*such as `pcre` and `gd`*) manually; see edit for fix (*above my obstructing inclusion of a `phpinfo()` dump*). – Dan Lugg Oct 31 '11 at 16:33