未命名

admin3年前IT技术1160

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


相关文章

sublime编译运行PHP

创建PHP编译系统添加 PHP 的 build system,如图所示, Tools->Build System-> New Build System :新建一个,默认的内容是:{&nbs...

二维码生成导航

http://twoyn.shengmake.nethttp://twalabo.shengmake.nethttp://twyilang.shengmake.nethttp://twyindu.sh...

excel在第三个空格插入数据

=LEFT(RIGHT(C63,LEN(C63)-FIND(" ",C63,FIND(" ",C63,FIND(" ",C63)+1)+1)...

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

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

magento1.9x系统加速

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

acme.sh 使用文档

acme.sh 使用文档

这是acme.sh的使用文档,介绍了如何使用ACME协议自动管理和获取SSL/TLS证书,包括安装、注册、手动和自动签发证书,以及自动部署和更新证书的过程。ACME是"Automatic C...

发表评论    

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