Re: Re: Function autoloading

From: Date: Sun, 01 Sep 2013 20:30:18 +0000
Subject: Re: Re: Function autoloading
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Nicolas,

On Sun, Sep 1, 2013 at 11:27 AM, Nicolas Grekas <
[email protected]> wrote:

> My previous message didn't push the point I wanted raise: don't we have a
> major problem related to at-run-time namespace resolution for functions and
> constants?
>
> Take this code: namespace foo { strlen("bar"); }
>
> Will you trigger an autoload for foo\strlen?
> I believe not because that would hurt performance too much.
> But then, how will you load function foo\strlen if it exists?
>
> Now take this code: namespace foo { bar(); }
>
> Will you trigger autoload for "foo\bar" first, then for "bar"?
> Only for "foo\bar"? But then, what if "bar" exists and just waits being
> autoloaded?
>
> I fail to see how autoloading functions is compatible with at-run-time
> namespace resolution.
>

So, here's how it works, by example:

namespace foo {
    use function biz\buz;
    use foo\bar;

    something(); // autoloaded as "something"
    buz(); // autoloaded as "biz\buz"
    bar\baz(); // autoloaded as "foo\bar\baz"
    \load\execute(); // autoloaded as "load\execute"
}

So basically, if the call uses "fallback" resolution, the autoload is only
attempted at the global resolution.

Does that make sense?

Anthony


Thread (72 messages)

« previous php.internals (#68821) next »