On Fri, 3 Jan 2020 at 14:39, tyson andre <tysonandre...@hotmail.com> wrote:
> > 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? > > The example you were thinking of would call \strlen on line 2, \Foo\strlen > on line 3, and \Foo\strlen on line 4. > (because the caching is per-opcode, not per-file or per-namespace) > Sorry, I should have been clearer - I wasn't asking for a literal answer based on any particular implementation, I was asking rhetorically what a user would expect to happen. Let's make the example a tiny bit more complex: namespace Foo; function one() { echo strlen('hello'); } function two() { echo Foo\strlen('hello again'); } 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. 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. Regards, -- Rowan Tommins [IMSoP]