1.如果不加命名空間
test1.php
<code><span><span>function</span><span>test</span><span>()</span> {</span><span>echo</span><span>'test1'</span>; }</code>
test2.php
<code><span><span>function</span><span>test</span><span>()</span> {</span><span>echo</span><span>'test2'</span>; }</code>
test.php
<code><span>require</span><span>'test1.php'</span>; <span>require</span><span>'test2.php'</span>;</code>
報錯:
2.加了命名空間
test1.php
<code><span>namespace</span><span>Test1</span>; <span><span>function</span><span>test</span><span>()</span> {</span><span>echo</span><span>'test1'</span>; }</code>
test2.php
<code><span>namespace</span><span>Test2</span>; <span><span>function</span><span>test</span><span>()</span> {</span><span>echo</span><span>'test2'</span>; }</code>
test.php
<code><span>require</span><span>'test1.php'</span>; <span>require</span><span>'test2.php'</span>; Test1\test(); <span>echo</span><span>'<br/>*************<br/>'</span>; Test2\test();</code>
以上就介紹了90 php 命名空間,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。