Lukas Kahwe Smith wrote:
>
> On 11.11.2009, at 11:44, Mikko Koppanen wrote:
>
>> On Wed, Nov 11, 2009 at 10:00 AM, Lukas Kahwe Smith
>> <m...@pooteeweet.org> wrote:
>>>
>>> On 11.11.2009, at 01:50, Greg Beaver wrote:
>>>
>>>> if (can_include($file)) {
>>>>   include $file;
>>>> }
>>>
>>>
>>> I am sure you focused on the technical aspects. Just wanted to say
>>> that for
>>> a name "can" is not ideal, because there is no gurantee that the
>>> file will
>>> not have syntax errors. As such something with "exists" is better (for
>>> example include_file_exists(), though also not ideal) .. Stas
>>> proposal of a
>>> "file_find()" is also good, but I think it would be nice to have
>>> "include"
>>> in the name.
>>>
>>
>> Isn't this what stream_resolve_include_path does?
>
> it might .. the doc's are sort of unclear .. since fopen optionally
> checks the include path. then again the name of the function implies
> that it does a search in the include path. the name is a bit long ..
> but i like the use of "resolve".
>
> so a byte code cache should cache the resolution of the path thereby
> speeding up the subsequent call to include? 

stream_resolve_include_path() as currently constructed could not be
intercepted, and is actually unable to process an include_path that
contains streams.  I'm guessing it was written long before PHP 5.3. 
This could be easily fixed by having stream_resolve_include_path call
zend_resolve_path() instead of doing its own internal calculations. 
With these changes, an opcode cache could easily cache the results.

As for your naming concerns, if we were to add an alias called
is_includable() to stream_resolve_include_path(), that would be much
clearer:

if (is_includable($file)) {
    include $file;
}

The assumption here is that we are simply testing whether the file
exists and whether php can actually read the file, not whether the file
has syntax errors.  A file with syntax errors is an exceptional
situation, and should be handled by a clear fatal error, imo.

Greg

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to