36

Is it possible to get extension version in php?

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

avasin
  • 9,186
  • 18
  • 80
  • 127

3 Answers3

55

I believe this is what you're looking for:

$version = phpversion("extensionName");

More information

EM-Creations
  • 4,195
  • 4
  • 40
  • 56
  • 3
    note that this does not work with `curl` & `mcrypt`(both return `false`), seems to have been there for a long time: https://bugs.php.net/bug.php?id=40582, no answer found. – samluthebrave May 11 '15 at 09:11
  • also doesn't work for PCRE (see link in comment above), but you can check the constant `PCRE_VERSION` for version info – webaware Jun 07 '16 at 23:04
  • 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. – Will Fastie Jan 31 '17 at 14:27
44

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.

Quolonel Questions
  • 6,603
  • 2
  • 32
  • 33
  • This is not working if you try to detect the version of an extension.dll what is not compatible with your php version – Radon8472 Aug 07 '18 at 20:03
1

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

<?php
    $ext = new ReflectionExtension('mysqli');
    var_dump($ext->getVersion());
?>
aagamezl
  • 49
  • 3
  • Provide some explanation – Amy Nov 13 '14 at 05:15
  • 2
    This returns the same version information as phpversion($extension). I checked 58 extensions, of which 30 returned version information. – Will Fastie Jan 31 '17 at 14:22
  • 1
    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) – Henk Poley Jul 07 '21 at 13:08
  • Correction, it returns false. – Henk Poley Jul 07 '21 at 13:15