On Fri, 3 Jan 2020 at 01:51, tyson andre <tysonandre...@hotmail.com> wrote:
> 1. It (first) looks for a function from the current namespace: A\B\foo(). > 2. It (next) tries to find and call the global function foo(). > 3. (Optional) NEW ADDITION: Next, if both functions were undefined, > the autoloader(s) attempt to autoload the function A\B\foo() > (and call it instead of throwing if found) before proceeding to step > (4.) > 4. NEW ADDITION: If both functions were undefined, > the autoloader(s) attempt to autoload the global function foo() > (and call it instead of throwing if found) before throwing an Error > I think running the autoloaders out of sequence from the actual name lookup is a recipe for confusion. Consider this case: namespace Foo; echo strlen('hello'); // Finds a global function at step 2, so doesn't trigger the autoloader echo Foo\strlen('hello'); // Explicitly namespaced function, so triggers the autoloader echo strlen('hello'); // Should this run \strlen or Foo\strlen? If we cache the resolution to global function at line 2, removing that line changes the rest of the program. If we don't cache it there, then what happens if we run this code in a loop? Admittedly, that ambiguity can already be introduced if you explicitly define the function between the two calls, but that can be worked around by pre-loading all functions for a namespace. The whole purpose of autoloading is that you don't need to think about when definitions are loaded, so this kind of case would be much more likely to bite people. Regards, -- Rowan Tommins [IMSoP]