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

8 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:Going back to DOS style... by Anonymous Coward · · Score: 4, Informative

    Uhm no. Because the DOS commands used '/' for indicating options as opposed to the '-' of the UNIX world.

  3. Re:HOLY FUCKING SHIT!?!?! by coryking · · Score: 4, Informative

    Except you just made a typo. It is "\" instead.

    Either way, most languages use either "." or "::" for namespaces

    # perl looks like
    use My::CPAN::Module qw();
    my $instance = My::CPAN::Module->new("junk");

    # c# looks like
    using System.Windows.Controls;

    System.Windows.Controls.ListBox box = new System.Windows.Controls.ListBox();

    # c++ looks like (I think)
    namespace Blah::Blah;

    # php will now look like
    $object_instance = new My\PEAR\Module("myvar");

    I'll leave the "looks" of PHP's method to the reader.

  4. Classes, namespaces, and subnamespaces by janwedekind · · Score: 4, Informative

    Looking at the IRC discussion it seems that they didn't have much of a choice.

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

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

  7. Re:Another fashionable addition for PHP: by ObsessiveMathsFreak · · Score: 4, Informative

    Goto's are useful. Labels are useful. Yes they can lead to problems, but so do things like pointers, dynamic typing, operator overloading, namespaces and automatic memory management. But they can also solve problems that are otherwise intractable, which is what the GP was trying to tell you. Dismissing them just because E. Djisktra said so is not really good enough.

    If you want an argument from authority, or just a good read, here's Donald Knuth on Structured Programming with GOTO Statements. You need to read that paper before you can have a proper opinion on the GOTO statement. Otherwise you're just adhering to dogma.

    --
    May the Maths Be with you!
  8. 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.