Maison >développement back-end >tutoriel php >91 php 命名空间1
1.使用命名空间:基础
<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></span></code>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介绍了91 php 命名空间1,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。