未命名

admin3年前IT技术1248

<?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();?>


相关文章

通过IP获取MAC地址

关键知识点:ARP缓存时间是十分钟;实现的命令是:第一步  ping  ip第二部  arp -a基础解释:在底层的网络通信中,两个节点想要相互通信,必须先要知道源与目标...

Hyper-V虚拟机固定IP地址(手把手教设置)

链接虚拟机修改网络配置文件输入指令sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0然后 输入  按  i  键 再按回车...

关于jquery升级至1.8版本之后的兼容问题Uncaught TypeError: $(...).size is not a function

关于jquery升级至1.8版本之后的兼容问题Uncaught TypeError: $(...).size is not a function

之前也遇到过这种问题Uncaught TypeError: $(...).size is not a function  控制台报错如上图,打开Frame.js可以看到里面定义大小...

javascript 的array数组保存到mysql数据库

 第一步在javascript里创建数组 var wordList = new Array();1第二步给后台传送数据之前要把数组变成字符串形式   wordL...

win10卸载服务 在Windows 10系统

在Windows 10系统中卸载服务可以通过以下步骤进行:打开运行窗口。按下Win键+R键,输入“services.msc”后回车,打开服务列表。1在服务列表中,找到需要卸载的服务。服务名称和显示名...

发表评论    

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