What does it mean?
It really means what it says and shows in the example. When importing a namespaced class, you should omit the first backslash:
use My\Full\Classname as Another; // recommended
use \My\Full\Classname as Another; // not recommended
The reason being that use
expects a fully qualified namespace. You cannot use a relative path. In other words if you are in the My\
namespace already, you cannot use Full\Classname
.
What's the purpose?
It's explained in the first chapter actually:
In the PHP world, namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions:
- Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.
- Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem, improving readability of source code.
So, the purpose is to shorten and/or to avoid clashes, e.g. when you have two classes called Foo and need to use both, you have to have a way to resolve that conflict (at least if you don't want to use the fully qualified name each time):
use My\Very\Long\Namespaced\Class\Named\Foo as Foo;
use My\Other\Foo as OtherFoo;
And then you can use
$foo = new Foo;
$otherFoo = new OtherFoo;
So that's short and simple and doesn't clash. There really isn't much more to it.