On 05/01/2020 18:03, tyson andre wrote:
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.
That would be the intuitive approach for a language,
but as mentioned earlier,
it would significantly harm performance of existing code for php 7
(slightly without an autoloader, more with autoloaders),
and I can't imagine that getting approved.


Yes, I'm fully aware of the downsides. I just think relaxing that constraint would lead to a horribly confusing language.


I'd considered that option, but that introduces its own surprises,
which I'd consider to have more frequent and significant impact on applications 
that start using this.

namespace NS;
function f1($x) {
      return mb_strlen($x) + 1;
}
function f2($x) {
      return \mb_strlen($x) * 2;
}

Calling f2() then f1() would work, but f1() then f2() would not work, because 
f1() wouldn't autoload.


True; again, it violates the user's expectation, which I think can be summed up this way:

- The autoloader for a function should run the first time that function would run if it was pre-defined.

That in turn stems from an even more fundamental expectation:

- An application using an autoloader should behave the same as one which defines all functions in advance.


The more I think about it, the more I think we should just be optimising for the case where everything *is* defined in advance. As far as I know, PHP's autoloading is an anomaly among programming languages, and maybe it has outlived its usefulness.


Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

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

Reply via email to