Re: Declare minimum PHP version required?

From: Date: Tue, 04 Feb 2014 18:59:18 +0000
Subject: Re: Declare minimum PHP version required?
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
2014.02.03. 7:59, "Yasuo Ohgaki" <[email protected]> ezt írta:
>
> 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
> [email protected]

I don't like the idea.
First I don't think that it is a good practice for a library to directly
terminate the execution of the application, and because this would be a
compile-time check, I don't think we could provide any sane way of allowing
the execution of the code.

I also think that the performance gain is too small to the average/small
users (compared to the usual low-hanging fruits like using an opcode cache,
proper autoloading, etc.) while  the big users would be doing the checks
installation-time anyways, so they wouldn't use it.

For general purpose applications (like drupal/wordpress/etc.) it wouldn't
be useful either, because they want nice and descriptive error screens
instead of php fatal errors which would most of the time just result in a
blank screen and some lines in the error log.

The only target audience would be the specific group of library developers
who think that the execution of their lib is more important than the app
which calls them, and for those people we already have version_compare()
and exit.

Ps: sent from my phone, sorry for the typos.


Thread (50 messages)

« previous php.internals (#72207) next »