Namespaces¶
Namespaces are a way to encapsulate items like classes, interfaces, enumerations, traits, functions, and constants, preventing naming conflicts between different parts of a program. They help organize and structure code, especially in larger projects where multiple developers may be contributing.
A namespace may not be called namespace. Otherwise, its name follows the same regex than other PHP structures: ^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$.
<?php
namespace a {
class x {
}
}
namespace b {
// a second class x, although distinct from the previous one
class x {
}
}
?>
See also Understanding PHP Namespaces: Organising Your Code.
Related : Use Alias, Fully Qualified Name, Subnamespaces, Collision, global Scope, Name, Namespace Name, Domain, include, Name Conventions, Naming Conflict, Prefix
Added in PHP 5.3