Re: Autoloading functions/consts without a performance impact
| From: | Rowan Tommins | Date: | Sun, 05 Jan 2020 18:48:16 +0000 |
| Subject: | Re: Autoloading functions/consts without a performance impact | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107994@lists.php.net to get a copy of this message | ||
On 05/01/2020 18:03, tyson andre wrote:
Yes, I'm fully aware of the downsides. I just think relaxing that constraint would lead to a horribly confusing language.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.
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) {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]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.