Space introduction method: useuse
keywords
The elements introduced by space are classes by default. If you want to introduce other elements, you must use the corresponding keywords :function
andconst
(if you need to introduce multiple elements of the same type, you need to use ",
" to separate them)
If You need to add multiple elements at the same time
If the introduced element already exists in the current space, there will be duplicate names. The solution is to use aliasesas
Keyword for renaming
If all elements in a space need to be introduced, you can also directly introducespace
"; } } namespace n2; class OK{ public function __construct() { echo __NAMESPACE__."
"; } } //引入空间 use n1\n2; new OK(); //访问的是n2\OK new n2\OK(); //使用引入空间的最后一级空间访问 ?>
Recommended:php tutorial,php video tutorial
The above is the detailed content of How to introduce another space element in a namespace?. For more information, please follow other related articles on the PHP Chinese website!