Declare minimum PHP version required?

From: Date: Mon, 03 Feb 2014 06:58:06 +0000
Subject: Declare minimum PHP version required?
Groups: php.internals 
Request: Send a blank email to internals+get-72042@lists.php.net to get a copy of this message
Hi all, I thought it might be good for us to have declaring minimum PHP version required to execute script. http://jp1.php.net/manual/en/control-structures.declare.php Something like <?php declare(php_version>='5.6.0'); // or PHP_VERSION_ID? using = as minimum as it could be a little faster // and no change in declare() syntax. declare(php_version=50600); If version mismatches, raise compile error and exit. Something like Compile error: PHP 5.6.0 or later is required to compile script. Your PHP version is 5.x.x. The same thing can be done by version_compare() and die(), but it does not make much sense executing script only to check PHP version and die, especially for libraries. For library, it is preferred to fail when it is included, not when it is executed. I wouldn't write version_compare() and die() for libraries, but I may use it if it's a declare(). If this is adopted widely, it may help transition to higher versions hoping users to consider compile error more seriously. Issue would be current behavior for unsupported declaration. $ php -r "declare(php_version=050600);" Warning: Unsupported declare 'php_version' in Command line code on line 1 It does not raise E_ERROR, but E_WARNING. Just an idea. Any comments? -- Yasuo Ohgaki yohgaki@ohgaki.net

« previous php.internals (#72042) next »