On Fri, 3 Jan 2020 at 15:21, tyson andre <[email protected]> wrote:
> > Now the behaviour of my program can completely change depending on which
> of
> > those functions I call first, which might even depend on user input.
> > Regardless of exactly how the cache works, that kind of unpredictability
> is
> > a recipe for disaster.
>
> It already does completely change depending on user input, without
> autoloading, in the same way.
>
Not really, the only way you could have the same dependency on call order
at the moment would be if it looked like this:
namespace Foo;
function one() {
echo strlen('hello');
}
function two() {
require_once 'functions/Foo/strlen.php';
}
At that point, it's pretty obvious that you're conditionally including a
definition, which is not the case with the original example.
> I assume you're arguing against autoloading without autoloading \NS\strlen
> every time
>
Yes, I'm saying that the autoloader should be called for each lookup, so
autoloading of Foo\strlen should come between checking if Foo\strlen is
defined, and checking if \strlen is defined.
>
> > The only way to make it predictable again is to pre-define the namespaced
> > function in my startup code, at which point I don't need function
> > autoloading.
>
> Other use cases would benefit from function autoloading, though.
Then maybe we should target the feature at those use cases - don't call the
autoloader *at all* unless we know the fully-qualified name, and give up
trying to "square the circle" by combining fallbacks with autoloading for
unqualified names?
Regards,
--
Rowan Tommins
[IMSoP]