Home  >  Article  >  Backend Development  >  Hierarchical management of php namespace

Hierarchical management of php namespace

无忌哥哥
无忌哥哥Original
2018-06-28 16:01:411553browse

* 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;}

//Qualified name: similar to relative path access

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

//Finally resolved to: one\two\Demo

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

//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;}

//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;;

// 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;

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!

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