<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc'; $TOC = array(); $TOC_DEPRECATED = array(); $PARENTS = array(); include_once dirname(__FILE__) ."/toc/language.namespaces.inc"; $setup = array ( 'home' => 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); ?> <div id="language.namespaces.nested" class="sect1"> <h2 class="title">Declaring sub-namespaces</h2> <p class="verinfo">(PHP 5 >= 5.3.0, PHP 7, PHP 8)</p> <p class="para"> 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: <div class="example" id="example-341"> <p><strong>Example #1 Declaring a single namespace with hierarchy</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">namespace </span><span style="color: #0000BB">MyProject\Sub\Level</span><span style="color: #007700">;<br /><br />const </span><span style="color: #0000BB">CONNECT_OK </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />class </span><span style="color: #0000BB">Connection </span><span style="color: #007700">{ </span><span style="color: #FF8000">/* ... */ </span><span style="color: #007700">}<br />function </span><span style="color: #0000BB">connect</span><span style="color: #007700">() { </span><span style="color: #FF8000">/* ... */ </span><span style="color: #007700">}<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> The above example creates constant <code class="literal">MyProject\Sub\Level\CONNECT_OK</code>, class <code class="literal">MyProject\Sub\Level\Connection</code> and function <code class="literal">MyProject\Sub\Level\connect</code>. </p> </div><?php manual_footer($setup); ?>