Home > PHP > PHP namespace separator

PHP namespace separator

December 31st, 2008

I honestly thought that the namespace separator for PHP was a done deal, namely ‘::’.  It was originally planned to introduce namespaces in PHP6, but they moved it to the upcoming PHP 5.3 and due to problems implementing that they made a last minute change to ‘\’.

A lot of people are happy that PHP will finally have support for namespaces, but a lot of people also think they made a really bad choice for the separator.
One of the best comments I found was on slashdot and it gives an overview of the separators for different programming languages:

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

My thoughts about this:

  • it makes PHP look inconsistent
  • it makes the introduction of namespaces in PHP look like a rush job, improvisation, some quick and dirty programming
  • if they encountered serious problems introducing namespaces in PHP 5.3, they should have postponed it to PHP6, like originally planned
  • it feels weird using a backslash on the left side of an assignment operator
  • it looks ugly

I don’t think I will be using namespaces anytime soon, because I will be using PHP 5.1.6 at work and PHP 5.2.5 on this shared hosting for a while longer, but when I have to I will just go with the flow like everybody else. Unless you choose for poor man’s namespacing (and be using very long classnames).

Just my 0.02 €

Trying to please everybody,
you’ll please no one.

PHP ,

  1. Harold
    February 18th, 2009 at 15:47 | #1

    Try typing a bit with the \ separator. You’ll be suprised how natural it feels :)

  1. No trackbacks yet.