Actually there is a difference, but not always (oh right).
In the use construct, you do not need to "specify" the leading \ . Inline you never have to if the class is in the same namespace, or if you are using import (imported using use ns ).
But sometimes you have to:
namespace foo; class bar extends \baz\Bar {
You are using the built-in class undefined / unknown / unimported, so you must specify its source.
Another example is classes with names that are not used in the namespace, inline:
namespace foo; $dt = new \DateTime;
The best practice (as a rule) is to import all the classes required by the current file. The usage statement is very, very, very, very cheap, so don't hold back.
namespace foo; use baz\Bar AS OtherBar; use \DateTime; class Bar extends OtherBar {
change 1
Also, be sure to use class name names with name names when passing them as strings, even if you are in the correct namespace:
namespace foo; $class = 'foo\bar';
Rudie
source share