namespace (namespace) is equivalent to functions and classes, dividing an area so that the same class can be required on the same page and functions with the same name can be used
: Rarely used in projects
<code><span>//name.php</span><span><?php</span><span>//命名要使用复合名称</span><span>namespace</span><span>me</span>\<span>mine</span>; <span><span>class</span><span>me</span>{</span><span>public</span><span><span>function</span><span>__construct</span><span>()</span>{</span><span>echo</span><span>'name'</span>.<span>'<br>'</span>; } <span>public</span><span><span>function</span><span>name</span><span>()</span>{</span><span>echo</span><span>'i use space'</span>.<span>'<br>'</span>; } } <span>//$me = new me();</span><span><span>function</span><span>me</span><span>()</span>{</span><span>echo</span><span>'is me'</span>.<span>'<br>'</span>; }</code>
<code><span>//common.php</span><span><?php</span><span><span>class</span><span>me</span>{</span><span>public</span><span><span>function</span><span>__construct</span><span>()</span>{</span><span>echo</span><span>'no namespace'</span>.<span>'<br>'</span>; } }</code>
<code><span><span><?php</span><span>//建议使用别名</span><span>use</span><span>me</span>\<span>mine</span><span>as</span><span>i</span>; <span>require</span><span>'./name.php'</span>; <span>require</span><span>'./common.php'</span>; <span>$me</span> = <span>new</span> i\me(); <span>$me</span>->name(); i\me(); <span>$com</span> = <span>new</span> me();</span></span></code>
The above has introduced the namespace of PHP, including espace content. I hope it will be helpful to friends who are interested in PHP tutorials.