> > old applications could maintain compatibility only > > by adding a simple autoloader that would alias the global > function/constant > > into the calling namespace > > So as a side-effect of calling any function, my namespace would get > polluted with all sorts of random names? That sounds like a messy > work-around. > > Obviously it would be just a temporary workaround.
> Okay, so take it back for a moment. > > The problem case is this, right? > > namespace Foo; > bar(); > > If the function Foo\bar() has not already been loaded, we fall back to > bar() in the global namespace. > > With a function-autoloader in place, we would need to trigger this for > every function-call from any namespace, and that's unacceptable. > I'm sorry, it's unacceptable for who? Only for not defined function it would be called. If I call the same function a thousand times, the autoload will be attempted just the first time, and if it doesn't work then the script would die, exactly like classes. Any project I know that uses functions define them one per file, and each file is required one by one. How is that different? Plus, there's opcache: function autoloading is not really autoloading but actually about "not having to maintain lists of require()s". Also, if you really think having one function per file is too much, you can always require everything in one go: ``` function autoloadFunction($functionFQN){ // $functionFQN = "\\foo\\bar\\functionName"; $namespace = substr($functionFQN, 0, strrpos($functionFQN, '\\')); require($namespace . '\\all_the_functions_and_constants.php'); } ``` > So what if, instead of trying to autoload everything by default, we make > it opt-in? Something like: > People clearly need this and I wouldn't mind if this was the solution. But, this is a workaround imho, and contrarily to what I've suggested, this wouldn't be temporary.