Re: Pre-RFC spitball - Namespace Load event

From: Date: Fri, 03 Jul 2026 12:49:52 +0000
Subject: Re: Pre-RFC spitball - Namespace Load event
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-131731@lists.php.net to get a copy of this message
Hi Michael, > On Jul 2, 2026, at 09:41, Michael Morris <tendoaki@gmail.com> wrote: > > This is tangential to the function autoload discussion. > > An idea that popped into my head an hour ago, that I don't have another PHP Dev to talk to > about, what if you could register a function that is called by PHP the first time it sees a > namespace declared? That's a neat idea ... > > This would allow functions and for that matter constants of the namespace to be declared before > they get called. It isn't as clean as waiting until the function call itself is being called, > but maybe that's for the best. After all, if you have a dozen 10 line utility functions do you > necessarily want 10 files. ... but do note that function autoloading need not be 1-file-per-function, as is the typical case with classes (cf. PSR-0 and PSR-4). For example, the Moto autoloader allows more-than-one class or function per file. https://github.com/motophp/autoload That's only one option for multiples-per-file, so that those "dozen 10 line utility functions" can be in a single file. -- pmj

« previous php.internals (#131731) next »