Re: Declare minimum PHP version required?

From: Date: Tue, 04 Feb 2014 06:34:03 +0000
Subject: Re: Declare minimum PHP version required?
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 02/03/2014 09:51 PM, Yasuo Ohgaki wrote:
I have to agree with Stas and Sara on this one. This is not the job of the language syntax. This is the package manager's job; once the code is installed (not compiled, installed), you shouldn't be changing your version anyway without knowing what you're doing / verifying on a test system anyway. If this were more like Javascript's "use strict", where it affected the parsing rules of that file, that would at least be useful (if potentially mind-bendingly painful for the engine; no I'm not suggesting we do that). But a shortcut for if (version_compare()) die; is not needed, and that would be a dumb way to go about implementing version requirements in the first place.
This assumption is not valid as I already wrote. There will be SCL in RHEL7 and there are tools like phpenv. Installing PHP does not have to be executing PHP.
I don't know what SCL is, nor what phpenv is. Thus "installing PHP does not have to be executing PHP" makes little sense to me as a sentence.
Version and module requirement checks are popular and I don't think it is dumb at all. It is dumb that if script didn't work as it should be due to version mismatch, isn't it?
Well usually it will fatal anyway if it's written for a too-new version. I know software has version checks in it; Drupal (the project I work on primarily) has had a version check in it for years... but in the installer, not in arbitrary non-installer files.
BTW, it is not a short cut of version check, but "elimination of run time check overheads". Many people don't understand what declare() is, it seems. declare() is compiler directive, *NOT* a function. Thus it could instruct what compiler should do at compile time. Since declare() is compiler directive, compiler may omit byte code for declare block. Therefore, run time overheads of declare block may be eliminated with byte code cache.
I can think of exactly one use case for compiling or not compiling a given file depending on the version, and that's for function backports (like the old PHP_Compat library, or the backport of the password hash functions from PHP 5.5.) Those are trivial enough to just wrap the require statement in a version_compare(). Or, really, the opcode overhead of that compared to the size of a typical code base these days is probably negligible.
Isn't checking requirements over and over a waste of resources?
Yes. So don't do it. :-) Really, I have no clue what the use case is here. --Larry Garfield

Thread (50 messages)

« previous php.internals (#72176) next »