Slashdot Mirror


PHP Gets Namespace Separators, With a Twist

jeevesbond writes "PHP is finally getting support for namespaces. However, after a couple hours of conversation, the developers picked '\' as the separator, instead of the more popular '::'. Fredrik Holmström points out some problems with this approach. The criteria for selection were ease of typing and parsing, how hard it was to make a typo, IDE compatibility, and the number of characters."

4 of 523 comments (clear)

  1. Re:I have to say they are working really hard.... by FooAtWFU · · Score: 5, Informative

    Oh, they've been at it for a while now ;)

    --
    The World Wide Web is dying. Soon, we shall have only the Internet.
  2. Re:so what's the problem here? by mysidia · · Score: 5, Informative

    The problem is not merely that it is different.

    The problem is they chose the ESCAPE character as a namespace separator.

    This is even worse than using $ as the namespace separator.

    Because of the problems it causes syntax highlighters, the problem it causes to programmer sanity when storing identifier names in a string.

    The problem it causes when searching through and sanitizing code.

    For example, since \ has a special meaning in the context of a regular expression, searching and replacing using regular expressions just got very painful.

    Copy and paste no longer works for searching and substituting.

    Refactoring just became a major bitch.

  3. Re:what wrong with by moderatorrater · · Score: 5, Informative

    As I remember, everything more complex than just outputting the value of the variable (ie calling a method, accessing a property, etc) requires you to use brackets inside of the string. Namespaces would work the same way without adding any complexity that wasn't already there.

  4. Re:It's all a joke by Requiem18th · · Score: 5, Informative

    And this is (one of) the many reasons PHP sucks:

    Java:
    Attribute/Method access: foo.bar
    Static method access:    Foo.bar
    Package access:          foo.bar.baz

    C#:
    Attribute/Method access: foo.bar
    Static method access:    Foo.bar
    Namespace access:        foo.bar.baz

    Python:
    Attribute/Method access: foo.bar
    Static method access:    Foo.bar
    Module access:           foo.bar.baz

    PHP:
    Attribute/Method access: $foo->bar
    Static method access:    Foo::bar
    Namespace access:        foo\bar\baz

    --
    But... the future refused to change.