首先创建三个文件: one.php、two.php、three.php
one.php
namespace ac; class Type { function getInfo(){ echo "this is one"; } }
two.php
namespace def; 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 acType; use defType as TwoType; // acType 类 $one_app = new Type(); $one_app2 = new Type(); $one_app3 = new Type(); // $one_app->getInfo(); // this is one // defType 类 $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