未命名

admin3年前IT技术1260

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


相关文章

设置apach多站点的配置方法

 Include conf/vhost/*.conf...

magento1.9x系统加速

1.设置magento数据库模型 为单表查询:   在System > Configuration > Catalog > FrontEnd设置 ‘U...

汇成制造行业CMS企业建站系统v11.1

汇成制造行业企业网站cms系统v11.1管理地址:http://您的网站/admin/login.asp后台帐号:admin后台密码:admin演示地址:˂a href="ceshi/zhizhao/...

excel选取某个字符左边所有内容

=LEFT(C4,FIND("-",C4)-1)...

错误0xC004F069非核心版本的计算机上运行slui.exe解决方法

错误0xC004F069非核心版本的计算机上运行slui.exe解决方法

Windows 10系统使用slmgr命令添加密钥时出现错误:“0xC004F069在运行Microsoft Windows非核心版本的计算机上,运行 slui.exe 0x2a 0xC00...

服务器端安装 Shadowsocks

服务器端安装 Shadowsocks

最简单、能直接用的 Shadowsocks(SS)服务端 + v2rayN 客户端配置教程,加密方式 aes-128-gcm,端口 255998。(假设你是使用 Linux 服务器(Debian/Ub...

发表评论    

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