Here we will introduce the usage of the php Tutorial namespace and the namespace keyword. in this article, we will introduce the use of the use command and how php resolves the namespace name. Namespacebakbaba; func...
Here we will introduce the usage of the php Tutorial namespace and the namespace keyword. in this article, we will introduce the use of the use command and how php resolves the namespace name.
namespace bakbaba;function bab(){ echo "bi";}namespace kkk;function k1(){ echo "k1";}
Bakbababab (); // use another namespace in the kkk namespace. Note the preceding
Use bakbaba as B; // it is still in the kkk namespace, but the following method is correct when using an alias:
# Use bakbaba as B; // do not use a number before
Bbab (); // when using the namespace under the alias, there should be no number in front of it
K1 (); // no error is returned when this function is called, indicating that use does not affect the current namespace
< ?php // application library 1 namespace applib1; const myconst = 'applib1myconst'; function myfunction() { return __function__; } class myclass { static function whoami() { eturn __method__; } } ?> lib2.php< ?php // application library 2 namespace applib2; const myconst = 'applib2myconst'; function myfunction() { return __function__; } class myclass { static function whoami() { eturn __method__; } } ?>
Fortunately, this piece of code is found in the manual, so other namespace content in the manual can be ignored. you can directly look at the following code.
Address:
Reprinted at will, but please attach the article address :-)