未命名

admin3年前IT技术1363

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


相关文章

二维码生成导航

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

Windows10家庭版添加Hyper-V的详细步骤

Windows10家庭版添加Hyper-V的详细步骤

转http://www.xitongcheng.com/jiaocheng/win10_article_60078.htmlHyper-V是微软提出的一种系统管理程序虚拟化技术,可以降低运作成本、提高...

Axure RP 8设置动态面板状态的方法

Axure RP 8设置动态面板状态的方法

设置动态面板状态需要注意鼠标单击需要设置面板状态,而不是显示隐藏,不然无法控制动态面板里的各个元件的显示与隐藏 ˂a href="post/523.html"˃...

php – DOMXpath – 获取一个元素的href属性和文本值[转]

原文https://stackoverflow.com/questions/6820429/domxpath-get-href-attribute-and-text-value-of-an-a-ele...

发表评论    

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