<?php
/*
别名和导入可以看做是调用 命名空间的一种快捷方式,php并不 支持导入函数或者常量
*/
namespace Blog\Article;
class Comment{
function test(){
return ‘aaa‘;
}
}
//创建一个BBS空间
namespace BBS;
//导入一个命名空间
use Blog/Article;
//导入命名空间后可使用限定名称调用元素
$artcle_comment = new Article\Comment();
echo $artcle_comment->test();
echo ‘<br/>‘;
//为命名空间使用别名
use Blog/Article as Arte;
$artcle_cpmment = new Arte\Comment();
echo $artcle_comment->test();
echo ‘<br/>‘;
//导入一个类
use Blog\Article\Comment;
$art_comment = new Comment();
echo $art_comment->test();
//为类使用别名
use Blog\Article\Comment as Comt;
//使用别名代替空间名
$art_comment = new Comt();
echo ‘<br/>‘;
echo $art_comment->test();
原文:http://www.cnblogs.com/ayanboke/p/6490595.html