PHPs Namespace Separator

Ovid on 2008-10-26T09:18:13

Many of you have already heard the PHP news. The rest of you may have wondered what that strange sound was. That was the sound of tens of thousands of developer's jaws dropping all at once. You see, PHP is getting namespaces and the delimiter is the backslash. Yup. The backslash: '\' (minus the quotes, obviously).

Apparently they were all set to go with the double-colon '::' separator when someone pointed out that this is what they use to call a static class function in PHP:

BloodyToys::giggle();

Uh oh. Now what do you do? Is "BloodyToys" a class or a namespace? In the Perl world, this might seem like a non-issue because unlike many other languages, we don't make a distinction between classes or namespaces. PHP does and this makes parsing problematic. I suppose that PHP could have simply died at compile-time if they found an ambiguous declaration (e.g., a giggle function defined in both a BloodyToys namespace and a BloodyToys class), but the developers decided not to do this and frankly, I have no idea why.

For more on this, I one PHP developer's comments on the new namespace decision. It will be interesting to see what comes of this.


Can't check at compile time

AndyArmstrong on 2008-10-26T10:14:12

They can't check reliably check at compile time - because they might not know - but you'd have thought they could check at runtime.

<rumour mode="joke">I heard that Microsoft bunged them a load of cash to make PHP namespaces look like Windows paths...</rumour>

People in glass houses&#x2026;

Dom2 on 2008-10-26T11:42:32

Don't forget that Perl originally used (and still supports) the apostrophe as a namespace separator!

The old package delimiter was a single quote, but double colon is now the preferred delimiter, in part because it's more readable to humans, and in part because it's more readable to emacs macros. — perlmod

-Dom

Re:People in glass houses&#8230;

chromatic on 2008-10-26T17:18:07

I hear that Perl's parser (for all of its complexity and maintenance horrors) is much more robust than PHP's parser. Ambiguity of parsing and difficulty of implementation are not primary concerns for Perl.

Re:People in glass houses&#8230;

pudge on 2008-10-30T23:00:04

use D'oh; # :-D