How do I use namespaces classes, functions, or constants in their own
namespace?

// using a class from the current namespace as a type hintfunction test(MyClass $typehintexample = null) {}// another way to use a class from the current namespace as a type hintfunction test(\foo\MyClass $typehintexample = null) {}

// extending a class from the current namespaceclass Extended extends MyClass {}

// accessing a global function$a = \globalfunc();

// accessing a global constant$b = \INI_ALL;?>

How does a name like \my\name or \name
resolve?

Names that begin with a \ always resolve to what they
look like, so \my\name is in fact my\name,
and \Exception is Exception.

There is no name conflict, even though the class MyClass exists
within the my\stuff namespace, because the MyClass definition is
in a separate file. However, the next example causes a fatal error on name conflict
because MyClass is defined in the same file as the use statement.

Before PHP 5.6 neither functions nor constants can be imported via the use
statement.

Before PHP 5.6 the only elements that are affected by use statements are namespaces
and class names. In order to shorten a long constant or function, import its containing
namespace.

<?phpnamespace mine;use ultra\long\ns\name;

$a = name\CONSTANT;name\func();?>

As of PHP 5.6 aliasing or importing function and constant names is allowed.

Dynamic namespace names (quoted identifiers) should escape backslash

It is very important to realize that because the backslash is used as an escape character
within strings, it should always be doubled when used inside a string. Otherwise
there is a risk of unintended consequences:

Inside a single-quoted string, the backslash escape sequence is much safer to use, but it
is still recommended practice to escape backslashes in all strings as a best practice.

Undefined Constants referenced using any backslash die with fatal error

Any undefined constant that is unqualified like FOO will
produce a notice explaining that PHP assumed FOO was the value
of the constant. Any constant, qualified or fully qualified, that contains a
backslash will produce a fatal error if not found.

When creating classes or calling static methods from within namespaces using variables, you need to keep in mind that they require the full namespace in order for the appropriate class to be used; you CANNOT use an alias or short name, even if it is called within the same namespace. Neglecting to take this into account can cause your code to use the wrong class, throw a fatal missing class exception, or throw errors or warnings.

In these cases, you can use the magic constant __NAMESPACE__, or specify the full namespace and class name directly. The function class_exists also requires the full namespace and class name, and can be used to ensure that a fatal error won't be thrown due to missing classes.

[Editor's note: that behavior is caused by a bug in PHP 7.0, which has been fixed as of PHP 7.0.7.]

Regarding the entry "Import names cannot conflict with classes defined in the same file".
- I found that since PHP 7.0 this is no longer the case.
In PHP 7.0 you can have a class with a name that matches an imported class (or namespace or both at the same time).

As nl-x at bita dot nl states in the note at http://www.php.net/manual/en/function.define.php, the constant "NULL" can be defined with define() case-sensitively, but can only be retrieved with constant(), leaving the meaning of NULL uppercase keyword as the only value of the type null.