> > namespace foo { > something(); // autoloaded as "something" > } >
That makes sense *for me* for many reasons, but IMHO that's too confusing for a wider adoption. Because this doesn't work for function foo\strlen, the only reasonable way to work with such an autoloader would be to avoid using dynamic namespace resolution by always using some "use function" or "use namespace". That's very fragile... I order not to be the one who kills a proposal and be constructive: Would some kind of namespace initializers be a good idea? That could work this way: Any time a non existing function or constant is required, a registered namespace initializer would be loaded. The big difference being that it would happen *BEFORE* fallback namespace resolution. The registered namespace loader would be given only the namespace part of the required symbol, and that would happen only once per namespace. That would have a performance impact, but I would be interested in seeing real benchmarks. May be we can find a way to make the mechanism light enough. For this performance reason, I would suggest having a registering function that take the exact namespace for which the loader matches as first argument: spl_namespace_register($namespace[, callable $autoload_function) $autoload_function would be called only for symbols in $namespace. What do you think ? Is it worth discussing that further? Nicolas