Re: [RFC] New core autoloading mechanism with support for function autoloading

From: Date: Tue, 11 Apr 2023 10:57:23 +0000
Subject: Re: [RFC] New core autoloading mechanism with support for function autoloading
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-119905@lists.php.net to get a copy of this message
On Mon, 10 Apr 2023 at 20:12, Anton Smirnov <sandfox@sandfox.me> wrote: > Hello George, > > I'm not sure I'm 100% correct but I think that this RFC still allows to > call different functions for the same code, just not in the same run. > > Consider this pseudocode: > > //- funcs.php > > namespace My; > > function myfunc(...) { ... } > function array_map(...) { ... } > > //- code1.php > > namespace My; > > myfunc(1); // autoload triggered > // bonus points if it's a different file or some obscure method > array_map(strlen(...), []); // My\array_map > > //- code2.php > > namespace My; > > // no prior autoload > array_map(strlen(...), []); // global array_map > No, array_map will trigger the autoloader (actually strlen() will trigger it once first) and the autoloader should then load the array_map function from the My namespace. However, if the autoloader does not correctly load the My\array_map() function then it will be bound to the global function. I can add some test cases for that if needed. > And if I understand the current order of execution correctly, here is a > more extreme example: > > //- moreextreme.php > > namespace My; > > if (some_random()) { > array_map('My\myfunc', []); // global array_map > } else { > array_map(myfunc(...), []); // My\array_map > } > > -- > Anton > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >

« previous php.internals (#119905) next »