On 15/08/2024 16:22, Rob Landers wrote:
Hello internals,

I've decided to attempt an RFC for function autoloading. After reading hundreds of ancient (and recent) emails relating to the topic along with several abandoned RFCs from the past, and after much review, I've decided to put forth a variation of a previous RFC, as it seemed the least ambitious and the most likely to work:

https://wiki.php.net/rfc/function_autoloading4


Hi Rob,

While brevity can sometimes be a virtue, I feel like there's a lot left to the reader's interpretation here.

Specifically, one of the main issues that has come up in previous discussions of the topic is the behaviour of unqualified function names, which check the current namespace first, then fall back to global scope. Your RFC implies an approach to this, but doesn't actually spell it out, nor discuss its pros and cons.

The fully qualified case is straight-forward: the autoloader is called, and if still not defined, an error is thrown. But for the unqualified case, there are multiple scenarios, and you only give the behaviour for one of them:

Defined in current namespace? | Defined in global namespace? | Proposed behaviour
------------------------------+------------------------------+--------------------------------------
No                            | No                           | Autoloader called, with prefixed name
No                            | Yes                          | ???
Yes                           | No                           | ???
Yes                           | Yes                          | ???

The third and fourth cases (where the function exists in the current namespace) are straight-forward, although it wouldn't hurt to spell them out: presumably, the namespaced function is used as now, so no autoloading is needed.

The complex case has always been the second one: the function doesn't exist in the current namespace, but *does* exist in the global namespace. (Or, an autoloader *defines* it in the global namespace.)

In concrete terms, what does this code output:

spl_autoload_register( function($function, $type) { echo "$function..."; }, type:SPL_AUTOLOAD_FUNCTION);

namespace Foo {
   foreach (['hello', 'goodbye'] as $word) {
      echo strlen($word), ';';
   }
}

a) "Foo\strlen...5;Foo\strlen...7;" (the autoloader is called every time the function is encountered) b) "Foo\strlen...5;7;" (the autoloader is called once, then somehow marked not to run again for this name
c) "5;7;" (the autoloader is never run for this code)


Note that there is an open RFC implementing option (b) by Gina and Dan here: https://wiki.php.net/rfc/core-autoloading Last I heard, Gina was still hoping to get back to it.


On a different note, there is no mention of autoloading namespaced constants in this RFC, unlike in some previous proposals. Is this a conscious decision to leave them out of scope, or an oversight?


Regards,

--
Rowan Tommins
[IMSoP]

Reply via email to