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

php uses alias to import namespace

无忌哥哥
Release: 2023-04-01 21:30:02
Original
1498 people have browsed it

* Use alias to import namespace

* Use of use keyword

//1. Declare a namespace one

namespace one ;
use one\two\three\Demo;
Copy after login

//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;}
Copy after login

//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;
Copy after login

//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;}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template