Home >Backend Development >PHP Tutorial >php uses alias to import namespace

php uses alias to import namespace

无忌哥哥
无忌哥哥Original
2018-06-28 16:04:401482browse

* 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn