Home >Backend Development >PHP Tutorial >php uses alias to import namespace
* Use alias to import namespace
* Use of use keyword
//1. Declare a namespace one
namespace one ; use one\two\three\Demo;
//If the current class also has one What should I do with the Demo class with the same name? Give the imported class an alias
use one\two\three\Demo as Demo1; class Demo1{public $name='Peter Zhu';} class Demo{public $name='Peter Zhu';} const SITE='PHP中文网'; function add($a,$b){return $a+$b;}
//Access in the current space: Class in one\two\three space
//Must add a long length The space prefix
echo (new two\three\Demo)->name; echo (new Demo)->name; echo (new Demo1)->name;
//2. Declare the namespace: one\two\three
namespace one\two\three; class Demo{public $name='朱老师';} const DOMAIN = 'www.php.cn'; function add($a,$b){return $a+$b;}
The above is the detailed content of php uses alias to import namespace. For more information, please follow other related articles on the PHP Chinese website!