Hi Lester,
On Mon, Feb 3, 2014 at 8:17 PM, Lester Caine <[email protected]> wrote:
> Yasuo Ohgaki wrote:
>
>> > >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
declare() is evaluated at compile time. It's not a usual function, but a
Zend engine directive. Therefore, it can be used for
declare(encoding='SJIS') which declare to compiler used encoding.
Since it is evaluated at compile time, run time check is not needed at all
when byte code cache is used.
There are many code out there checks if (!extention_loaded(foo')) die('You
need foo'). This is waste of CPU resources once it is checked. These
requirements for scripts may be evaluated at compile time and script runs a
little faster.
Regards,
--
Yasuo Ohgaki
[email protected]