Home >Backend Development >PHP Problem >What does php version mean?

What does php version mean?

藏色散人
藏色散人Original
2021-12-13 09:11:072872browse

phpversion is a function in PHP used to obtain the current PHP version. Its usage syntax is "phpversion(string $extension = ?): string".

What does php version mean?

#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.

What does php version mean?

phpversion

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

phpversion — Get the current PHP version

Description

phpversion(string $extension = ?): string

Returns a string containing the currently running PHP interpreter or extended version information.

Parameters

extension

Optional extension.

Return value ¶

If the optional parameter extension is specified, phpversion() will return the version of the extension. If there is no corresponding version information, or the extension is not enabled, false is returned.

Example #1 phpversion() Example

<?php
// prints e.g. &#39;Current PHP version: 4.1.1&#39;
echo &#39;Current PHP version: &#39; . phpversion();
// prints e.g. &#39;2.0&#39; or nothing if the extension isn&#39;t enabled
echo phpversion(&#39;tidy&#39;);
?>
示例 #2 PHP_VERSION_ID 范例和用法
<?php
// PHP_VERSION_ID 自 PHP 5.2.7 起有效,
// 如果我们的版本低于该版本,则用以下代码来模拟 
if (!defined(&#39;PHP_VERSION_ID&#39;)) {
    $version = explode(&#39;.&#39;, PHP_VERSION);
    define(&#39;PHP_VERSION_ID&#39;, ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
// PHP_VERSION_ID 定义为一个数字,PHP 版本越新,数字越大。
// 它的定义是以下的表达式:
//
// $version_id = $major_version * 10000 + $minor_version * 100 + $release_version;
//
// 现在我们可以通过 PHP_VERSION_ID 来检查 PHP 版本,
// 而不用每次都必须用 version_compare() 来检查 PHP 是否支持某个功能。
//
// 比如,我们在此可以定义一系列 PHP_VERSION_* constants 常量,
// 而在 5.2.7 之前的版本并没有被定义。
if (PHP_VERSION_ID < 50207) {
    define(&#39;PHP_MAJOR_VERSION&#39;,   $version[0]);
    define(&#39;PHP_MINOR_VERSION&#39;,   $version[1]);
    define(&#39;PHP_RELEASE_VERSION&#39;, $version[2]);
    // 等等, ...
}
?>

Comments

Note:

This information also exists in the predefined constant PHP_VERSION. More version information can be obtained using the constants PHP_VERSION_*.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does php version mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn