Retrieve extension version in php
Asked Answered
O

3

39

Is it possible to get extension version in php?

get_loaded_extensions returns only loaded extentions names, but not versions :(

Ockeghem answered 31/1, 2013 at 12:51 Comment(3)
Only if an extension provides a way of querying its version.Daune
@Daune All extensions provide a way of their version being queried: $version = phpversion("extensionName");.Rettarettig
What is meant by extension? Extension to Apache, PHP, or browser?Daphne
R
56

I believe this is what you're looking for:

$version = phpversion("extensionName");

More information

Rettarettig answered 31/1, 2013 at 12:53 Comment(3)
note that this does not work with curl & mcrypt(both return false), seems to have been there for a long time: bugs.php.net/bug.php?id=40582, no answer found.Various
also doesn't work for PCRE (see link in comment above), but you can check the constant PCRE_VERSION for version infoBaptista
OpenSSL is an interesting case, Neither this method nor the Reflection method below return any version information. But OpenSSL instantiates the constants OPENSSL_VERSION_TEXT and OPENSSL_VERSION_NUMBER. Clearly there is no standardized way of getting versions from extensions.Shaughn
C
50

At the command line, where extension is the extension name.

php --re extension | head -1

If unsure of the extension name, list extensions with php -m.

Cavity answered 29/9, 2017 at 16:21 Comment(1)
This is not working if you try to detect the version of an extension.dll what is not compatible with your php versionMarmara
E
1

http://php.net/manual/en/reflectionextension.getversion.php

<?php
    $ext = new ReflectionExtension('mysqli');
    var_dump($ext->getVersion());
?>
Ellen answered 13/11, 2014 at 4:56 Comment(4)
Provide some explanationTshirt
This returns the same version information as phpversion($extension). I checked 58 extensions, of which 30 returned version information.Shaughn
Under PHP 7.1-7.3 (more?), both phpversion("extension name") and ReflectionExtension return the PHP version (not the extension version). I guess this is something like the wrapper version, which gets automatically bumped up during release. Not that useful. It does check whether the extension exists (if it doesn't exist it returns null)Zeus
Correction, it returns false.Zeus

© 2022 - 2024 — McMap. All rights reserved.