Re: Pre-RFC spitball - Namespace Load event
| From: | Larry Garfield | Date: | Fri, 03 Jul 2026 16:35:06 +0000 |
| Subject: | Re: Pre-RFC spitball - Namespace Load event | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131739@lists.php.net to get a copy of this message | ||
On Fri, Jul 3, 2026, at 7:32 AM, Michael Morris wrote:
> And this applies for use statements as well. For example, if `use
> A\foo;` is foo a class? a function, a constant? Who knows, but this is
> the moment to find out and execute this handler.
It's known because the syntax says what it is.
use Foo\Bar; // Bar is a class, or a namespace prefix.
use function Foo\Bar\baz; // baz is a function.
use const Foo\Bar\Beep; // Beep is a constant.
This feels somewhat similar to Python, where a given module can have an __init__.py file that is
automatically loaded the first time the module is referenced. I'm not sure how well that maps
into PHP (see previous module/package/namespace threads), but it's an interesting model to
explore for function autoloading.
--Larry Garfield