未命名

admin3年前IT技术1633

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


相关文章

搭建apache2.4+php5.6环境

工具下载地址apache2.4 下载地址:http://httpd.apache.org/php5.6 下载地址:http://windows.php.net/download#php-5.6一、安装...

MYSQL替换第一个匹配的值

UPDATE zq_newsSET zq_content = CONCAT(    REPLACE (      &nb...

GoogleTranslate-基于Google翻译的免费火车头PHP翻译插件[转]

前言之前各国语言标识见本文下面的“语言标识”部分。3.2.新建一个标签名叫“翻译标签”的标签用来设置需要翻译的标签和保存翻译后内容的标签,数据获取方式选...

linux 挂载win7共享文件夹的方法

mount -t cifs -o user=administrator,password=000000 //192.168.1.2/gongxiang /mnt/share...

美国人喜欢自己动手装修房子

参考文献::http://www.sohu.com/a/291910017_100085730原因有三:1.美国人工贵       ...

批量修改文件后缀名

新建***.bat在里面写入ren *.* *.gif运行***.bat...

发表评论    

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