On 09/08/2016 18:44, Rasmus Schultz wrote:
On Tue, Aug 9, 2016 at 6:17 PM, Rowan Collins<rowan.coll...@gmail.com>  wrote:

>>In other words, calls to substr() does not trigger the resolve - a
>>statement like "use function substr" on the other hand, does.
>
>Ah, I see. The problem with that is, you still have to explicitly list every
>function you're going to use, so you might as well just use require_once, or
>call "load_function('substr')" directly.
Well, no - there is still the issue of file names and paths becoming a
dependency, besides issue of having to locate the file in the first
place.

Sure, there is a small advantage over raw require statements, because you're wrapping the file-location logic in a function, which can be a bit more flexible. But that doesn't actually need the engine to do anything special:


Proposed:

function autoload_function($name) {
require_once FUNCTION_ROOT . str_replace('\', PATH_SEPARATOR, $name) . '.php';
}
register_function_autoloader('autoload_function');

use function Acme\Util\foo; // calls autoload_function('Acme\Util\foo');
use function Acme\Util\bar; // calls autoload_function('Acme\Util\bar');


Current PHP:

function load_function($name) {
    if function_exists($name) return;
require_once FUNCTION_ROOT . str_replace('\', PATH_SEPARATOR, $name) . '.php';
}

load_function('Acme\Util\foo');
load_function('Acme\Util\bar');


All we'd really gain is a standard "name" for load_function (i.e. the "use" keyword), and I guess a built-in registry for chaining multiple callbacks together when you run it.

Regards,

--
Rowan Collins
[IMSoP]


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to