码迷,mamicode.com
首页 > Web开发 > 详细

PHP命名空间-总结

时间:2016-09-20 01:30:56      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

首先创建三个文件: one.php、two.php、three.php

one.php

namespace a\b\c;

class Type {
    function getInfo(){
        echo "this is one";
    }
}

two.php

namespace d\e\f;

class Type {
    function getInfo(){
        echo "this is two";
    }
}

three.php

class Type {
    function getInfo(){
        echo "this is three";
    }
}

index.php

require_once(‘one.php‘);
require_once(‘two.php‘);
require_once(‘three.php‘);

use a\b\c\Type;
use d\e\f\Type as TwoType;

// a\b\c\Type 类
$one_app = new Type();
$one_app2 = new Type();
$one_app3 = new Type();
// $one_app->getInfo(); // this is one

// d\e\f\Type 类
$two_app = new TwoType();
$two_app2 = new TwoType();
$two_app3 = new TwoType();
// $two_app->getInfo(); // this is two

// 顶层类
$three_app = new \Type();
$three_app->get_info(); // this is three

 

PHP命名空间-总结

标签:

原文地址:http://www.cnblogs.com/jiangxiaobo/p/5887290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!