未命名

admin3年前IT技术1378

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


相关文章

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

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

google apptore在线打包下载工具

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

汇成企业网站管理系统v46

汇成企业网站管理系统v46官方下载:˂a href="download/huichengv46.rar" target="_blank"˃下载地址一汇成企业网站管理系统v4.6汇成企业网站管理系统为中...

KindEditor设置网址绝对路径

 KindEditor 4.1.2版本,在上传图片的时候 设置为绝对路径被这个问题困扰了很久,最终搞定,竟然是如此之简单。   方法如下:   1、打...

汇成装潢行业企业网站系统vII2.3

汇成装潢行业企业网站系统vII2.1管理地址:http://您的网站/admin/login.asp后台帐号:admin后台密码:admin˂a target="_blank" href="hangy...

ubuntu 远程连接 22 端口

安装OpenSSHUbuntu缺省没有安装SSH Server,使用以下命令安装:sudo apt-get install openssh-server openssh-client不过Ubuntu缺...

发表评论    

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