标题解释了它,但这是我试图做的:
if (!defined(PHP_VERSION_ID) || PHP_VERSION_ID < 50400) {
trigger_error('PHP version 5.4 or above is required to run this code. Please upgrade to continue...', E_USER_ERROR);
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,这是正在发生的事情:
var_dump(PHP_VERSION_ID); // returns int(50404)
var_dump(defined(PHP_VERSION_ID)); // returns bool(false)
Run Code Online (Sandbox Code Playgroud)
根据php.net页面,defined您可以这样做:
<?php
// PHP_VERSION_ID is available as of PHP 5.2.7, if our
// version is lower than that, then emulate it
if (!defined('PHP_VERSION_ID')) {
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
// PHP_VERSION_ID is defined as …Run Code Online (Sandbox Code Playgroud) php ×1