未命名

admin3年前IT技术1189

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


相关文章

汇成电动工具行业企业网站系统v12.1

汇成电动工具行业企业网站系统v12.1˂a target="_blank" href="download/jixie/jixieddgjv121.rar"˃官方下载汇成企业网站管理系统为中小企业免费建...

批量修改文件后缀名

新建***.bat在里面写入ren *.* *.gif运行***.bat...

google apptore在线打包下载工具

https://apkpure.com/cn/apk-downloader-browser-extension?install=true...

GIt后悔药:还原提交操作(谨慎操作)

GIt后悔药:还原提交操作(谨慎操作)

GIt后悔药:还原提交操作(谨慎操作)一、背景:偶尔会遇到git的版本分支的文件被误改的情况,需要还原,此篇文章可能会帮助到你。PS:来理解下 Git 工作区、暂存区和版本库概念,可以更好的理解以下的...

推广导图

推广导图

  ...

15天学会php视频教程下载

 下载链接百度网盘下载...

发表评论    

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