Why are the PHP namespaces different compared to C++?

From: Date: Thu, 06 Sep 2012 21:30:33 +0000
Subject: Why are the PHP namespaces different compared to C++?
Groups: php.internals 
Request: Send a blank email to internals+get-62877@lists.php.net to get a copy of this message
Hi, I was just using the PHP namespaces for the first time and noticed a difference that i really didn't expect. (No, i won't start complaining about the slash based namespace). In C++ when you type: using std; Then you can use all methods/classes/whatever is defined in std without typing std. so: std::cout becomes just cout. In PHP that's a bit different. Lets take this as an example: ================================= namespacetst.php <?php namespace Some\Long\Namespace; Class SomeClass { } Now the one using that "SomeClass" has to do something like this: index.php use Some\Long\Namespace; $oClass = new Namespace\SomeClass(); ================================= Yes, you can also do: index.php use Some\Long\Namespace\SomeClass; $oClass = new SomeClass(); But i'm wondering why the "use Some\Long\Namespace" doesn't work like the C++ one. Since i would have guessed that adding that use will give me access to all the methods/classes/whatever that live within that namespace _without_ having to prefix it with the last part of the namespace. I hope someone can shed some light over this. Regards, Mark

« previous php.internals (#62877) next »