Re: Pre-RFC spitball - Namespace Load event
| From: | Michael Morris | Date: | Fri, 03 Jul 2026 16:41:45 +0000 |
| Subject: | Re: Pre-RFC spitball - Namespace Load event | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131740@lists.php.net to get a copy of this message | ||
On Fri, Jul 3, 2026 at 12:35 PM Larry Garfield <larry@garfieldtech.com>
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.