array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'it', ), 'this' => array ( 0 => 'language.namespaces.nested.php', 1 => 'Sub-namespaces', ), 'up' => array ( 0 => 'language.namespaces.php', 1 => 'Namespaces', ), 'prev' => array ( 0 => 'language.namespaces.definition.php', 1 => 'Namespaces', ), 'next' => array ( 0 => 'language.namespaces.definitionmultiple.php', 1 => 'Defining multiple namespaces in the same file', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'language/namespaces.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

Declaring sub-namespaces

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Much like directories and files, PHP namespaces also contain the ability to specify a hierarchy of namespace names. Thus, a namespace name can be defined with sub-levels:

Example #1 Declaring a single namespace with hierarchy

<?php
namespace MyProject\Sub\Level;

const
CONNECT_OK = 1;
class
Connection { /* ... */ }
function
connect() { /* ... */ }

?>
The above example creates constant MyProject\Sub\Level\CONNECT_OK, class MyProject\Sub\Level\Connection and function MyProject\Sub\Level\connect.