tags:

views:

337

answers:

3

Someone remind me why "." is not used as the namespace separator? I don't think the "." character is used anywhere else in PHP at all, unless I am mistaken.

+11  A: 

It's used to join strings.

For example:

$age = 30;
$text = "You are " . $age . " years old";

Reusing it for namespaces would create a dangerous ambiguity.

rspeed
+7  A: 

As mentioned by others, the dot is already taken for String concatenation.

Here's the chart the PHP developers used to pick the separator. Apparently \ got good marks on "typo-vulnerability", "IDE compatibility", and "number of chars"

EDIT: I just sat down and read the IRC conversation where \ was decided upon, and they were very good about their approach to it and exploring all other options. In short, anything else brought along a can of worms. The only knock on \ was that people would freak out about it, but they had the cojones to go through with it. Good for them. It was the difference between namespaces for classes only or having to wait until 6.0 versus getting the whole shebang right now.

Paolo Bergantino
A: 

If you are not already using '.' for string concatination ( which presumably you are not) you should begin as it is a joy once you get used to it, also you miss it in other languages.

Other string concat uses of . as an operator in php

.=  add to end of string being assigned to

Edit (removed =. from list my mistake).

Toby Allen
Please let me know where =. is referred to in the PHP.net docs as a valid operator.
Alister Bulman
It doesn't work. $var = '4567';$var =. '123';die($var);You'll get a `Parse error: syntax error, unexpected '.'` error.
Jrgns