Re: [PHP-DEV] Pre-RFC spitball - Namespace Load event

[email protected] (Michael Morris)
Newsgroups php.internals
Message-ID <CAEUnE0cWWcz6hcAtkR97d=pnk9=Z6BNYETuRqO-VB6FfwOLJmw@mail.gmail.com>
On Fri, Jul 3, 2026 at 12:35 PM Larry Garfield <[email protected]>
wrote:

> 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.
>

I had forgotten about that. It may simplify things then. Hmm...


>
> 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
>

I was aware of the Python approach, but I'm also aware of how beloved magic
file names are in PHP (as in, not - see the argument over treating an
extension differently, let alone a reserved file name).

Anyway, the main reason I brought this up is I cannot recall this exact
approach being discussed before. I don't have the expertise to determine if
the path is viable.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.