Hierarchical management of php namespace

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

* Hierarchical management of namespaces

* 1. Unqualified name: No space prefix is ​​used before the name of the space member, similar to accessing the current directory

//Declare namespace one

namespace one ;
class Demo{public $name='Peter Zhu';}
const SITE='PHP中文网';
function add($a,$b){return $a+$b;}
Copy after login

//Qualified name: similar to relative path access

tow\Demo 会自动加上当前空间前缀:one
Copy after login

//Finally resolved to: one\two\Demo

echo (new two\Demo)->name,&#39;<br>&#39;;
Copy after login

//Declare namespace two,two It is a subspace of one

namespace one\two;
class Demo{public $name=&#39;朱老师&#39;;}
const  SITE = &#39;www.php.cn&#39;;
function add($a,$b){return $a+$b;}
Copy after login

//Unqualified name: similar to access in the current directory

//No need to add a space prefix for access in the current space

echo (new Demo)->name,&#39;<br>&#39;;
Copy after login

// Fully qualified name: Starting from the global space, similar to starting from the root directory

//Starting from the current one\two\, to access members of another space, start from the root

echo (new \one\Demo)->name;
Copy after login

The above is the detailed content of Hierarchical management of php 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!