Reputation: 9981
In PHP there are two namespacing operators:
\
and ::
::
is used for internal namespacing, e.g:
namespace example;
class Foo {
public static $bar = 'hello';
}
I can access $bar
and other members of the Foo
class via: Foo::$bar
The full namespaced name of Foo
however is not example::Foo
, it is example\Foo
, and the full namespaced name of $bar would be example\Foo::$bar
What was the reason or rationale for using the two operators rather than sticking with one consistent operator that already existed?
Upvotes: 2
Views: 110
Reputation: 51411
You should take a peek at the namespace separator RFC, which calls out the actual arguments used in favor of and against the backslash.
The main reason why ::
wasn't picked was due to the possible ambiguity it caused when doing scope resolution. Given that namespaces can be aliased (use \Foo\Bar as Baz;
), all sorts of hilarious hijinks could be caused.
Upvotes: 4
Reputation: 14163
The ::
is the Scope Resolution Operator and is only ment to access static classes. It has nothing to do with the namespace. Also the namespacing has been added in PHP 5.3, so long after static classes.
I guess thats why they use two different operators (for two different goals)
Upvotes: 4