phpversion()
phpversion() — Gets the current PHP version.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns a string containing the version of the currently running PHP parser or extension.
Signature
phpversion(?string $extension = null): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $extension | ?string | An optional extension name. |
Return value
Returns the current PHP version as a string. If a string argument is provided for extension parameter, phpversion() returns the version of that extension, or false if there is no version information associated or the extension isn't enabled.
Example
A runnable snippet:
// Prints e.g. 'Current PHP version: 8.3.12' echo 'Current PHP version: ' . phpversion(); // Prints e.g. '1.22.3' or nothing if the extension isn't enabled echo phpversion('zip');
Changelog
| Version | Change |
|---|---|
| 8.0.0 | extension is nullable now. |
See also
version_compare(), phpinfo(), phpcredits(), zend_version()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page phpversion() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.