Namespace, But Far In The Name¶
<?php
// Not allowed
namespace namespace {}
//syntax error, unexpected namespace-relative name "namespace\A", expecting "{"
namespace namespace\A {}
// namespace may be used, but not in first position
// surely, not a good idea
namespace A\namespace {
const B = 1;
}
namespace A {
echo namespace\namespace\B;
}
?>
Namespaces can be named anything, except namespace. That keyword is used as a prefix, on a name (class, function, constant, etc.) to represent the current namespace, and allow for relative sub-namespaces.
Then, the namespace keyword cannot be used as the first part of a namespace, as it would conflict with the namespace relative part.
But it is possible to use namespace later in the name.
See Also¶
PHP Error Messages¶
PHP Features¶
Last updated: 14 July 2026