Home > Article > Backend Development > Hierarchical management of php namespace
* 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,'<br>';
//Declare namespace two,two It is a subspace of one
namespace one\two; class Demo{public $name='朱老师';} const SITE = 'www.php.cn'; 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,'<br>';
// 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!