O'Reilly logo

PHP 7 Quick Scripting Reference, Second Edition by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Mikael Olsson 2016

Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_26

26. Namespaces

Mikael Olsson

(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/namespaceclass MyClass {}

To assign the construct to another namespace, a namespace directive is defined. Any code constructs below the namespace directive belong to that namespace. The naming convention for namespaces is all lowercase.

namespace my;// Belongs ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required