On 08/08/2016 21:15, Rasmus Schultz wrote:
A function resolver would simply need to return a callable:
register_function_resolver(function ($name) {
if ($name === "html") {
return function ($str) {
return htmlspecialchars($str, ENT_HTML5);
};
}
if (substr($name, 0, 5) === "iter\\") {
require_once VENDOR_PATH."/nikic/iter/src/bootstrap.php";
return $name;
}
});
This mechanism is probably a lot easier to explain and understand -
and works equally for global or namespaced functions.
I don't quite follow what you're suggesting here. When does this
"function resolver" get called? Why does returning a callable rather
than just defining the function help with the problems we've been
discussing?
Okay, so it doesn't deal with namespaced constants, and maybe this is
me being opinionated, but who's going to import constants one by one?
Constants are usually better off grouped together in a class. Although
I don't suppose there's any reason this concept couldn't be expanded
to work for constants as well, for completeness at least - though I
have doubts that very many people would care...
It's not a case of importing constants - or, in most cases, functions -
one by one. As I've mentioned a couple of times, an RFC on static
classes [https://wiki.php.net/rfc/abstract_final_class] and various
similar discussions are frequently met with "you shouldn't be using a
class to group static items, use a namespace instead". For that we need
"namespace autoloading", which in practice means autoloading any of the
items you can put in a namespace. We can already autoload classes, so
that leaves constants and functions.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php