Home  >  Article  >  Backend Development  >  What does PHP_VERSION mean?

What does PHP_VERSION mean?

(*-*)浩
(*-*)浩Original
2019-10-12 09:31:043528browse

What does PHP_VERSION mean?

PHP_VERSION (string)

The current PHP version, expressed in the string form "major.minor.release [extra]". (Recommended learning: PHP video tutorial)

For example:

<?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]);

    // 等等, ...
}
?>

Note:

These Information is also present in the predefined constant PHP_VERSION. More version information can be obtained using the constants PHP_VERSION_*.

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