Home >Backend Development >PHP Tutorial >91 php namespace 1
1. Use namespace: Basics
<code><span><span><?php</span><span>namespace</span><span>Foo</span>; <span><span>function</span><span>strlen</span><span>()</span> {</span><span>echo</span><span>'hello'</span>; } <span>const</span> INI_ALL = <span>3</span>; <span><span>class</span><span>Exception</span> {</span>} <span>$a</span> = strlen(<span>'hi'</span>); <span>// 调用命名空间 Foo 的strlen()</span><span>$aa</span> = \strlen(<span>'hi'</span>);<span>//调用全局函数strlen</span><span>$b</span> = \INI_ALL; <span>// 访问全局常量 INI_ALL</span><span>$c</span> = <span>new</span> \<span>Exception</span>(<span>'error'</span>); <span>// 实例化全局类 Exception</span><span>echo</span><span>$a</span> . <span>'<br/>'</span>; <span>echo</span><span>$aa</span> . <span>'<br/>'</span>; <span>echo</span><span>$b</span> . <span>'<br/>'</span>; <span>echo</span><span>$c</span> . <span>'<br/>'</span>; </span></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 91 PHP namespace 1, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.