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
Why not? That's what PHP does - executing scripts.
included, not when it is executed. I wouldn't write version_compare() and
I don't understand - what is the difference? In PHP including and
executing is the same thing.
I think version_compare works just fine.
I works, but it requires CPU time for it and evaluation is delayed at
run time, not compile time. Isn't it nice to know requirement is not met?
We may extend declare() more. For example, loaded extensions.
declare(module='pgsql,openssl');
With this, we could eliminate code like
if (!extension_loaded('foo')) {
die('You need foo module');
}
if (!extension_loaded('bar')) {
die('You need bar module');
}
With opcache loaded extension check may be completely skipped.
Evaluation at compile time and run time differs.
I don't see how one can eliminate checking if a module is available. I do not load MySQL on my systems so if someone tries to run a script requiring MySQL they need a warning that it's not available. The build of PHP running ensures that the available built in modules are of the right version, but it's the third party libraries that I need to ensure are compatible with the version of PHP I'm trying to run, and that the necessary extensions for that library are loaded. Stuff updated to PHP5.5 may not work on the systems that are still running PHP5.4 for compatibility reasons ...