A pre-RFC discussion on the PHP internals mailing list proposes a new namespace load event mechanism: a callback registered via spl_namespace_register() that fires the first time PHP encounters a namespace declaration. The idea would allow functions and constants within a namespace to be declared before they are called, potentially enabling namespace-level autoloading without requiring one file per function. The thread explores open questions around callback invocation order for nested namespaces (e.g., Foo\Bar\Baz), how use statements should interact with the hook, wildcard loading syntax (use A\*), and how the engine could track already-initialized namespaces via callback return values. A respondent notes that existing tools like the Moto autoloader already support multiple functions per file as an alternative approach.

9m read timeFrom externals.io
Post cover image
316 Impressions