Mix PHP and namespaces, get weirdness

October 30, 2008 – 11:33 am Tags:

In 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.

Share this:
  1. 10 Responses to “Mix PHP and namespaces, get weirdness”

  2. W

    I vote for | :S

    By Harro on Oct 30, 2008

  3. 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

  4. 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

  5. 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 ~


    would read a lot better for me then


    not to mention that my regex sense would kick in and I would see it as:

    ame pace


    By Harro on Oct 31, 2008

  6. ? 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

  7. I suggest following namespace separator:

    So we have for namespace foo, class bar and static method baz this:


    I think it’s very readable.

    By Thomas on Oct 31, 2008

  8. Wasn’t really serious about the ?, but I can’t remember ever using ! as part of the syntax

    By Harro on Oct 31, 2008

  9. rofl… I’m an idiot.. ! == negative.. or ! != positive πŸ˜›

    By Harro on Oct 31, 2008

  10. 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

  1. 1 Trackback(s)

  2. Jan 25, 2009: Retad PHP trivs Γ€ndΓ₯ » Artopod

Post a Comment

You can use some HTML (a, em, strong, etc.). If you want to post code, use <pre lang="PHP">code here</pre> (you can replace PHP with the language you are posting)