Home >Backend Development >PHP Tutorial >90 php namespace
1. If you don’t add a namespace
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>
Error:
2. Added namespace
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>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
The above has introduced the 90 PHP namespace, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.