未命名

admin2年前IT技术904

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


相关文章

VB生成的ASP封装access数据库dll代码

 这篇文章以VB生成的DLL封装ASP代码来连接数据库(以Access数据库为例)。一般情况下我们在用ASP连接Access的数据库时通常都会进行如下的操作 '//Proconn....

15天掌握php

˂a href="download/php/第一课--15天掌握php.zip" target="_blank"˃第一课...

服务器2012打开远程端口,Windows Server 2012远程默认端口3389的修改

服务器2012打开远程端口,Windows Server 2012远程默认端口3389的修改

Window Server2012 修改远程桌面端口号Win + R 输入 regedit 打开注册表编辑器1、修改注册表项1HKEY_LOCAL_MACHINE/System/CurrentCont...

汇成机械行业企业网站系统v11.1

汇成机械行业企业网站系统v11.1˂a target="_blank" href="download/jixie/jixiehangye11.rar"˃官方下载汇成企业网站管理系统为中小企业免费建立属...

短链接伪静态

if (!-f $request_filename){ rewrite (.*) /index.php;}...

L2TP端口

1701,1702,4500,500...

发表评论    

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