Re: Not autoloading functions

From: Date: Sun, 29 Jan 2017 19:03:02 +0000
Subject: Re: Not autoloading functions
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-98023@lists.php.net to get a copy of this message
On 29/01/2017 17:56, Wes wrote:
Hi Rowan, I probably wasn't clear enough. How is having to write use namespace Foo\Bar\Baz; better than require_once("../Foo/Bar/Baz/functions.php");
OK, your last question just mentioned putting multiple functions in one file, not that you were addressing that particular proposal. Those are very different parts of the conversation. In an ideal world, just calling "\Foo\Bar\Baz\frobnicate()" would trigger an autoloader, and that autoloader could decide to require_once one big file if that's what the library author wanted. To an extent, I agree that requiring you to import a namespace in order to autoload it is perhaps too much of a compromise. There is some advantage over a plain require_once, though, in that you don't need to hard-code into your application the directory layout of some other library; it would be more akin to having a global function like "load_function_definitions($namespace);" Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#98023) next »