首页 > Web开发 > 详细

php use

时间:2017-03-02 15:07:34      阅读:196      评论:0      收藏:0      [点我收藏+]

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

 

php use

原文:http://www.cnblogs.com/ayanboke/p/6490595.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!