
PHP5's new namespace separator - a backslash?!
by Cameron
The Internet is pretty much blowing up right now over the news that the guys upstairs building PHP have decided that they're going to use \ as the separator for the new namespaces implementation in PHP 5.3.
For those of you who don't understand Namespaces, the above link will explain them, but essentially, all classes in PHP at the moment are global, which means developers who are building code libraries or modules to use in other applications have to prefix their classes in order to prevent ambiguity, which can lead to some pretty long and unwieldly class names.
The reason for the \ operator is pretty simple, the . operator is already used for concatenation, so that's right out, but the popular :: operator, which is currently being used for calling static methods, is also being ruled out, given the possibility for ambiguity, as follows:
namespace Foo;
function bar() {
echo "Namespace Foo";
}
Foo::bar();
Which is fine, but then...
class Foo {
static function bar() {
echo "Class Foo";
}
}
Foo::bar();
Uh oh! So instead of resolving the conflict at compile time (which IMO is the correct way to handle this issue), the PHP team have decided to use the \ operator instead, so we're going to have
Foo\bar();
Ugh. I'm unimpressed. It is my sincere hope that this changes before the final 5.3 release, I mean, it's just syntax, but these things are important to get right, and so far it appears the only people who think this is the right way about it are the PHP devs themselves.

Looks fine to me.
Post new comment