A pre-RFC discussion on the PHP internals mailing list proposes a new hook mechanism called spl_namespace_register() that would fire a callback the first time PHP encounters a namespace declaration. The idea aims to enable function and constant autoloading at the namespace level, rather than per-symbol. Discussion covers key design questions: whether callbacks should receive the full namespace string or be called per sub-namespace, how use statements interact with the hook, and where in the engine the handler should fire (on namespace declaration, before class autoloading, and before undefined function/constant errors). Rowan Tommins offers a detailed breakdown of how the three trigger points would work in practice, noting it elegantly sidesteps the global-vs-namespace sequencing problem that plagues function autoloading proposals. Comparisons to Python's __init__.py module loading pattern are raised, though PHP's resistance to magic filenames is noted as a concern.

35m read timeFrom externals.io
Post cover image
177 Impressions