PHP: phpversion - Manual (original) (raw)

(PHP 4, PHP 5, PHP 7, PHP 8)

phpversion — Gets the current PHP version

Description

Parameters

extension

An optional extension name.

Return Values

Returns the current PHP version as a string. If a string argument is provided forextension parameter, phpversion() returns the version of that extension, or [false](reserved.constants.php#constant.false) if there is no version information associated or the extension isn't enabled.

Changelog

Version Description
8.0.0 extension is nullable now.

Examples

Example #1 phpversion() example

<?php// 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');?>

Example #2 [PHP_VERSION_ID](reserved.constants.php#constant.php-version-id) example and usage

`<?php/**

Notes

Note:

This information is also available in the predefined constant**[PHP_VERSION](reserved.constants.php#constant.php-version)**. More versioning information is available using the [PHP_*_VERSION](info.constants.php#constant.php-windows-version-major) constants.

Note:

Some extensions may define their own version number. However, most bundled extension will use the PHP version as their version number.

See Also

Found A Problem?

cHao

12 years ago

If you're trying to check whether the version of PHP you're running on is sufficient, don't screw around with `strcasecmp` etc.  PHP already has a `version_compare` function, and it's specifically made to compare PHP-style version strings.

<?php
if (version_compare(phpversion(), '5.3.10', '<')) {
    // php version isn't high enough
}
?>

burninleo at gmx dot net

9 years ago

Note that the version string returned by phpversion() may include more information than expected: "5.5.9-1ubuntu4.17", for example.

pavankumar at tutorvista dot com

15 years ago

To know, what are the {php} extensions loaded & version of extensions :

<?php
foreach (get_loaded_extensions() as <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mo>=</mo><mo>&gt;</mo></mrow><annotation encoding="application/x-tex">i =&gt; </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6986em;vertical-align:-0.0391em;"></span><span class="mord mathnormal">i</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=&gt;</span></span></span></span>ext)
{
   echo <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>e</mi><mi>x</mi><mi>t</mi><msup><mi mathvariant="normal">.</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo>=</mo><msup><mo>&gt;</mo><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mi mathvariant="normal">.</mi><mi>p</mi><mi>h</mi><mi>p</mi><mi>v</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">ext .&#x27; =&gt; &#x27;. phpversion(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7519em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">t</span><span class="mord"><span class="mord">.</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span><span class="base"><span class="strut" style="height:0.791em;vertical-align:-0.0391em;"></span><span class="mrel"><span class="mrel">&gt;</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">.</span><span class="mord mathnormal">p</span><span class="mord mathnormal">h</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">ers</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mopen">(</span></span></span></span>ext). '<br/>';
}
?>