Am 11.12.2007 um 19:00 schrieb Stanislav Malyshev:
The problem I see with that is that if I have an application that
uses a 3rd-party library which does not use namespaces, I need to
use ::LibClass everywhere. Until they switch to namespaces - then I
need to touch hundreds and thousands lines of code. If LibClass
were looked up in the global namespace, too, I could simply add the
appropriate import statements at the top of each file.
But also it means that namespaced library would be influenced by any
use code around, which was exactly the thing we tried to avoid.
Anyways, the process you described seems flawed in another fashion:
It looks up a class in the namespace first, then an internal php
class, then it tries an autoload. That does not make sense. Lets
say I run some
Actually, it does :)
code as you described, and there is a class C(), but it's not been
autoloaded yet. The internal class C is used. Then, later, the
autoloading of A::B::C() is somehow forced. Now, if the same code
runs again, a different class is used. That sounds like nonsense.
Not, it's not nonsense - try to find other way that allows
overriding internal class names and doesn't force exhaustive
autoload search on each access to internal class - and you'll
understand why it makes sense.
Ah. Yes, that makes perfect sense to me. The logical solution must be
then, however, not to implement namespaces at all, or requiring code
that is either namespaced or has imported a namespace to do sth like
"use __php__;", as others suggested last week. I understand the reason
for the behavior from an implementational standpoint, but I think it
really is obvious that such a namespace solution would be completely
useless, as it would not be possible under any circumstances to
provide code that works in a reliable fashion.
Or, as an alternative, introduce an optional third argument to
spl_autoload_register where people can give a namespace name for which
the autoloading should be performed. That would cut down overhead
since just the autoload functions of currently imported namespaces
would have to be called.
I don't really think, though, that doing something like use __php__;
is a tall order, is it? It would only be necessary for those that
consume namespaces in their code via "use" statements, hence no BC
break.
- David
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php