© Mikael Olsson 2021
M. OlssonPHP 8 Quick Scripting Referencehttps://doi.org/10.1007/978-1-4842-6619-9_26

26. Namespaces

Mikael Olsson1  
(1)
Hammarland, Finland
 

Namespaces provide a way to avoid naming conflicts and to group namespace members into a hierarchy. Any code may be contained within a namespace, but only four code constructs are affected: classes, interfaces, functions, and constants.

Creating Namespaces

A construct that is not included in a namespace belongs to the global namespace.
// Global code/namespace
class MyClass {}
To assign the construct to another namespace, a namespace directive is defined. Any code constructs below the namespace directive belong to that namespace. A common naming convention for namespaces is to use all lowercase ...

Get PHP 8 Quick Scripting Reference: A Pocket Guide to PHP Web Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.