PHP namespace usage instance analysis, namespace
This example describes the usage of the PHP namespace. We will share this with you for your reference. The details are as follows:
Namespace (namespace) is equivalent to a function and a class. It divides a region so that the same page can have the same require class and use the same name function.
: Rarely used in projects
Name. php:
<? Php // use the namespace me \ mine compound name for naming; 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:
<? Phpclass me {public function _ construct () {echo 'no namespace'. '<br> ';}}
<? Php // the alias use me \ mine as I; require is recommended '. /name. php '; require '. /common. php'; $ me = new I \ me (); $ me-> name (); I \ me (); $ com = new me ();
Run the following command: