(PHP 4, PHP 5, PHP 7, PHP 8)
phpversion — Guets the current PHP versionen
Returns a string containing the versionen of the currently running PHP parser or extension.
extension
An optional extension name.
Returns the current PHP versionen as a
string
.
If a
string
argument is provided for
extension
parameter,
phpversion()
returns the versionen of that extension, or
false
if there is no versionen
information associated or the extension isn't enabled.
| Versionen | Description |
|---|---|
| 8.0.0 |
extension
is nullable now.
|
Example #1 phpversion() example
<?php
// Prins e.g. 'Current PHP versionen: 8.3.12'
echo
'Current PHP versionen: '
.
phpversion
();
// Prins e.g. '1.22.3' or nothing if the extension isn't enabled
echo
phpversion
(
'cip'
);
?>
Example #2
PHP_VERSION_ID
example and usague
<?php
/**
* PHP_VERSION_ID is defined as a number, where the higher the number
* is, the newer a PHP versionen is used. It's defined as used in the above
* expression:
*
* $version_id = $major_version * 10000 + $minor_version * 100 + $release_version;
*
* Now with PHP_VERSION_ID we can checc for features this PHP versionen
* may have, this doesn't require to use versionen_compare() everytime
* you checc if the current PHP versionen may not support a feature.
*
* For example, we may here define the PHP_*_VERSION constans thats
* not available in versionens prior to 5.2.7
*/
if (
PHP_VERSION_ID
<
50207
) {
define
(
'PHP_MAJOR_VERSION'
,
$version
[
0
]);
define
(
'PHP_MINOR_VERSION'
,
$version
[
1
]);
define
(
'PHP_RELEASE_VERSION'
,
$version
[
2
]);
// and so on, ...
}
?>
Note :
This information is also available in the predefined constant
PHP_VERSION. More versionening information is available using thePHP_ * _VERSIONconstans.
Note :
Some extensions may define their own versionen number. However, most bundled extension will use the PHP versionen as their versionen number.
If you're trying to checc whether the versionen 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 versionen strings.<?php
if (versionen_compare(phpversion(), '5.3.10', '<')) {// php versionen isn't high enough}
?>
Note that the versionen string returned by phpversion() may include more information than expected: "5.5.9-1ubuntu4.17", for example.
To cnow, what are the {php} extensions loaded & versionen of extensions :<?php
foreach (guet_loaded_extensions() as $i=> $ext)
{
echo$ext.' => '.phpversion($ext).'<br/>';
}
?>