Home >Backend Development >PHP Tutorial >PHP namespace namespace usage example analysis
The examples in this article describe the usage of PHP namespace namespace. Share it with everyone for your reference. The details are as follows:
namespace (namespace) is equivalent to functions and classes. It divides an area. This way, the same class can be required on the same page and the same name can be used. Function
: It is rarely used in projects
name.php:
<?php //命名要使用复合名称 namespace me\mine; class me{ public function __construct(){ echo 'name'.'<br>'; } public function name(){ echo 'i use space'.'<br>'; } } //$me = new me(); function me(){ echo 'is me'.'<br>'; }
common.php:
<?php class me{ public function __construct(){ echo 'no namespace'.'<br>'; } }
<?php //建议使用别名 use me\mine as i; require './name.php'; require './common.php'; $me = new i\me(); $me->name(); i\me(); $com = new me();
The running effect is as follows:
I hope this article will be helpful to everyone in PHP programming.
For more articles related to PHP namespace namespace usage example analysis, please pay attention to the PHP Chinese website!