Mix PHP and namespaces, get weirdness
October 30, 2008 – 11:33 am Tags: PHPIn an interesting decision, the PHP devs have decided to use a backslash, \, as the namespace separator. This is a bit… curious.. choice of a character.
They apparently had a long discussion about their choices, but really, couldn’t they just have used ::, as the manual showed for a while? It’s starting to feel like the fact that PHP was not designed with all these features in mind is starting to show more and more.
The argument that if you used :: as the separator would confuse between static calls is a bit weird, too. Python for example uses . for the namespace separator, method/property access and static method/property access and it works just fine. Now, I don’t know if PHP’s and Python’s internals differ greatly, but they’re both dynamic languages, so at least there shouldn’t be any implementation problems standing in the way for using the same character.
I’ve used languages with definitely weirder syntax than this, but it just seems weird, especially since PHP’s syntax is otherwise so similar to languages like C++. While some people seem to think this will make PHP much worse somehow, I think I’ll eventually get used to seeing the backslash in code, when we actually get 5.3 stable. It just seems really odd now.
RSS feed:Subscribe!












9 Responses to “Mix PHP and namespaces, get weirdness”
W
T
F
I vote for | :S
By Harro on Oct 30, 2008
That’s the binary OR operator - with the same logic that :: or . can’t be used because it’s used elsewhere, that can’t be used either =)
By Jani Hartikainen on Oct 30, 2008
Well.. at least it’s not an escape character in a case where it is most often used: strings.
The whole autoload functionality is based around loading a file/class based on a string.. and now they want to use the escape character for split it.
Ok.. let’s use ? because that’s just as clueless
By Harro on Oct 30, 2008
Actually.. I thought a bit about it and it’s actually weird that they only looked at the \ as a single character.
What about: ! or ~
my~name~space
my!name!space
would read a lot better for me then
my\name\space
not to mention that my regex sense would kick in and I would see it as:
my
ame pace
By Harro on Oct 31, 2008
? and ! are already being used as well… =)
I would not like ~ at all. I don’t know about your keyboard, but on mine it requires three keys: alt+ยจ (it’s next to enter in finnish layout) and space.
By Jani Hartikainen on Oct 31, 2008
I suggest following namespace separator:
..
So we have for namespace foo, class bar and static method baz this:
Foo..Bar::baz()
I think it’s very readable.
By Thomas on Oct 31, 2008
Wasn’t really serious about the ?, but I can’t remember ever using ! as part of the syntax
By Harro on Oct 31, 2008
rofl… I’m an idiot.. ! == negative.. or ! != positive
By Harro on Oct 31, 2008
Still don’t see how that would interfere btw..
I still think it’s a better option then \ :S
By Harro on Oct 31, 2008