未命名

admin3年前IT技术1332

<?php

namespace Article;

class Comment { }


namespace MessageBoard;

class Comment { }


//调用当前空间(MessageBoard)的Comment类

$comment = new Comment();


//调用Article空间的Comment类

$article_comment = new \Article\Comment();

?>


别名和导入

别名和导入可以看作是调用命名空间元素的一种快捷方式。PHP并不支持导入函数或常量。

它们都是通过使用use操作符来实现:

<?phpnamespace Blog\Article;class Comment { }//创建一个BBS空间(我有打算开个论坛)namespace BBS;//导入一个命名空间use Blog\Article;//导入命名空间后可使用限定名称调用元素$article_comment = new Article\Comment();//为命名空间使用别名use Blog\Article as Arte;//使用别名代替空间名$article_comment = new Arte\Comment();//导入一个类use Blog\Article\Comment;//导入类后可使用非限定名称调用元素$article_comment = new Comment();//为类使用别名use Blog\Article\Comment as Comt;//使用别名代替空间名$article_comment = new Comt();?>


相关文章

KindEditor得不到textarea值的解决方法

  下面以 KindEditor 4.x 版本为例说明,先贴上正确的代码:         &nb...

服务器2012打开远程端口,Windows Server 2012远程默认端口3389的修改

服务器2012打开远程端口,Windows Server 2012远程默认端口3389的修改

Window Server2012 修改远程桌面端口号Win + R 输入 regedit 打开注册表编辑器1、修改注册表项1HKEY_LOCAL_MACHINE/System/CurrentCont...

解决Cannot load php7apache2_4.dll into server导致无法启动Apache

萌新在面对服务端开发使用PHP搭配Apache时会遇见Cannot load php7apache2_4.dll into server 例如 01 最最最主要的问题 Apache...

在hyper-v安装centos7后与windows10共享文件夹

 挂载Windows共享文件夹的方法:1.在windows10宿主机下新建一个共享文件夹,比如叫share_win,并将其设为共享文件夹。2.在CentOS下,执行命令:mount ...

Axure RP 8设置动态面板状态的方法

Axure RP 8设置动态面板状态的方法

设置动态面板状态需要注意鼠标单击需要设置面板状态,而不是显示隐藏,不然无法控制动态面板里的各个元件的显示与隐藏 ˂a href="post/523.html"˃...

JS小数运算出现多为小数问题的解决方法

 asfasf Number类型:Number类型是ECMAScript中最常用和最令人关注的类型了;这种类型使用IEEE754格式来表示整数和浮点数值(浮点数值在某些语言中也被成...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。