Defining namespacesAlthough any valid PHP code can be contained within a namespace, only the following types of code are affected by namespaces: classes (including abstracts and traits), interfaces, functions and constants.
Namespaces are declared using the Example #1 Declaring a single namespace
The only code construct allowed before a namespace declaration is the declare statement, for defining encoding of a source file. In addition,
no non-PHP code may precede a namespace declaration, including extra whitespace:
Example #2 Declaring a single namespace
In addition, unlike any other PHP construct, the same namespace may be defined in multiple files, allowing splitting up of a namespace's contents across the filesystem. |