首页 > 代码库 > PHP命名空间-总结
PHP命名空间-总结
首先创建三个文件: 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命名空间-总结
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。