One of the first things I tried when I seriously started exploring
namespaces was the ideal of dynamic runtime loading. Consider class \A\Foo.
 I have a project that has \B\Foo extends \A\Foo.  For that project though I
want the autoloader to pull an unqualified request for "Foo" from \B\Foo
even if this comes up in the A namespace.  That currently isn't possible -
the autoloader receives the argument "\A\Foo" from the A namespace whether
new Foo or new A\Foo or new \A\Foo was the origin code.

This leads to my second problem though - even if the autoloader gets to know
the difference and reacts accordingly, what happens if \A\Foo gets
explicitly asked for in the \A namespace after "Foo" was asked for. I don't
know how to resolve this either. So I gave up.

Anyway, My only real gripe with namespaces is that they have no affect on
variables.  This I feel is a major implementation error because it runs
counter to how all other languages I've encountered handle namespaces. I've
lost count of how many people I've had to point this out to on sitepoint -
the expectation for programmers coming to PHP is that namespaces will
segregate variables.

It also means that "static" classes become the key means to keep registries
for those that use them. Coupled with the current situation with functions
that can't be autoloaded, this will lead to a lot more var/function hives in
code bases.  It's not a particularly testable pattern due to the hidden
dependencies that are created, and becomes a headache over time. Encouraging
the pattern at a language level isn't the worst thing that's ever occurred
(that would be magic_quotes and register_globals) but it's almost in the
same ballpark in my opinion.

I don't see the harm in having a function autoloader and don't understand
the rationale behind the resistance to it. The resistance is futile anyway -
all that's really happening is people move to making functions members of
static classes as a kludge.

All that said, I'm not going to worry myself too much about it as it doesn't
affect my coding approach. I don't use global functions and my only static
class is a bootstrap factory which gets the rest of the code working and
isn't accessible from that code once it starts.

Reply via email to