On Tue, Aug 9, 2016 at 6:17 PM, Rowan Collins <rowan.coll...@gmail.com> wrote:

>> In other words, calls to substr() does not trigger the resolve - a
>> statement like "use function substr" on the other hand, does.
>
> Ah, I see. The problem with that is, you still have to explicitly list every
> function you're going to use, so you might as well just use require_once, or
> call "load_function('substr')" directly.

Well, no - there is still the issue of file names and paths becoming a
dependency, besides issue of having to locate the file in the first
place.

So there is still very much a purpose to this.

Importing all classes with use-statements is good practice anyhow, and
- it forces you to document at the top of your file which elements
you're referencing outside of the local namespace. Of course, that's
opinion, but it's a common opinion - you don't see too much code in
the wild with inline qualified class references, most everyone has a
leading set of use-statements in every file.

Actually, now that I think of it, for that reason, I might actually be
okay with only qualified references triggering auto-loading after all
- this would never become an issue at all, because I'd qualify
everything with use-statements anyhow.

Though I do think it would be somewhat easier to *explain* this
feature, if it was simply triggered by the use-statement, not by the
circumstance of whether the name is or isn't qualified, because it's
not always obvious from looking at the code - you'd have to look at
the use-statements first and then correlate those with function-calls
and figure it out, every time you look at a file. That mental overhead
is eliminated by just having the use-statement trigger auto-loading.

Also, come to think of it, triggering the auto-loader could still be
deferred, for performance reasons, even if the use-statement is what
triggers is - so it wouldn't aggressively trigger the auto-loader when
the use-statement is encountered, but rather the first time the a
function imported with a use-statement is called. That would be more
consistent with how class resolution works.

I think maybe this could work after all??

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

Reply via email to