--------------------------------------------------------------------------------------------------
One. PHP namespaces primarily address three conflicting issues: constants, functions, classes
Popular understanding: namespace is equivalent to building a directory, namespace the following code in the directory, and outside the distinction.
/*|---------------------------------|namespace Example |@ black-eyed poet <www.chenwei.ws>|------------------------------- --*/namespace myself;function Var_dump(){ Echo100;}Var_dump(100);//calling a custom function (relative path mode)\myself\Var_dump(100);//Calling custom functions (absolute path mode)\Var_dump(100);//Call Global (System function)
Note: namespace cannot have any code before, except declare (); Multiple files can use the same namespace, but the content defined under the same namespace cannot be conflicting. Namespace supports sub-namespaces, such as: namespace \myself\good, which is equivalent to the concept of multi-level catalogs.
Two. Cases where multiple namespaces exist in the same file
1.
/**
* chenwei.ws
*/
namespace Nihao\shijie;namespace Hello\world; function Test () { //... .. }// consecutive naming, the following code will use the second namespace, and all successive naming is meaningless.
2.
/**/namespace nihao\shijie{ function test_one ()
{ //...... };} namespace hello\world{ function test_two ()
{ //........ }}\nihao\shijie\test_one (); \hello\world\test_two ();
The use of multiple namespaces within the same file, mainly for projects to merge multiple PHP scripts in the same file, is not advocated in practice!
Three. Name resolution rules (several concepts)
1. Unqualified Name: The name does not contain a namespace delimiter, such as: Myself
2. Qualified Name: The name contains a namespace separator, such as: Nihao\shijie
3. Fully qualified name: The name contains a delimiter and begins with a namespace delimiter, such as: \nihao\shijie (that is, the concept of an absolute path)
------------------------------------------------------------------------------------------------