Hello Gregory, Tuesday, November 4, 2008, 5:15:35 PM, you wrote:
> Christian Schneider wrote: >> Lukas Kahwe Smith wrote: >>> one could also do >>> 1) ns >>> 2) global >>> 3) autoload >> >> I'm in favour of this (if it avoids performance problems) as I don't see >> a problem with giving global priority over autoload. > Hi, > This is the current name resolution. The problem is that: > <?php > namespace foo; > $a = new Exception(); ?>> > will instantiate foo::Exception only if the class already exists, but > will instantiate Exception otherwise. This defeats autoload's purpose > for existing. We've been over this before. It's dangerous. > There is one essential difference between classes and > functions/constants: autoload. > The only time the question of load order and fallback becomes and issue > is when code is not explicitly loaded. In other words, a developer who > is relying upon an external function will do this at some point before > calling the function: > <?php > include 'path/to/code/containing/function/source.php'; ?>> > In other words, PHP expects you to actually load the source of functions > or constants you're going to be using in advance of using it. > This, I believe, is a reasonable expectation. > Classes, however, do *not* share this same expectation, because > autoload's explicit purpose is to allow using classes *before* their > source has been loaded. > In other words, it is perfectly all right to have a different name > resolution for classes than we have for functions and constants because > of this different expectation. It is dangerous to fallback for classes > prior to autoload, but it is not at all dangerous for > functions/constants because the expectation is different. > For this reason, the only resolution that we should be considering is: > classes: > 1) try ns::class > 2) autoload ns::class > 3) fail Since we can stack autoload we could provide a c-level autoload function that does the default lookup. function global_autoload($name) { if (($p = strrpos($name, '\\')) !== false) { $name = substr($name, $p); if (__NAMESPACE__ == substr($name, 0, $p -1) && class_exists("\\$name")) { use "\\$name"; // if we find a way to do this at C-levle } } } > functions/constants: > 1) try ns::function/ns::const > 2) try internal function/const > 3) fail. > Note that I say "try internal" because the only purpose behind allowing > this is to make it easier to use PHP's built-in functionality. Any > userspace stuff should be specifically \prefixed or imported via use. > And (yes) we need import for functions. > Greg > P.S. my mail server has been down for almost a week, apologies to anyone > who is wondering why I haven't replied to your message, I probably > didn't get it. Best regards, Marcus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php