未命名

admin3年前IT技术1087

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


相关文章

Android Studio下载sdk失败的解决方案

在浏览器打开这个网站http://ping.chinaz.com/dl.google.com或者:https://www.ping.cn/ping/dl.google.com他会列出一个ip列表,挨个...

解决Win+x打开终端提示无法找到wt.exe,无法打开windows终端

C:\Windows\System32\WindowsPowerShell\v1.0查看一下powershell是否可以打开,如果可以打开则说明系统的powershell终端还在,引用的读取路径被篡改...

L2TP端口

1701,1702,4500,500...

使用excel的翻译功能

使用excel的翻译功能

1.打开审阅2.打开翻译就可以实现翻译...

设置apach多站点的配置方法

 Include conf/vhost/*.conf...

ASP中Connection对像封装dll解决方案

asp代码保密一直是令人头痛的问题,目前没有非常好的解决方案,无非用vb编译成dll,但工作量实在太大,于是一直苦苦寻求着另一种途径。。。  中午,突然灵感一发,“为什么不尝试用加密数据库...

发表评论    

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