Namespaces can be used starting from php5.3, and namespaces are used to prevent duplicate elements of namespaces. The elements of a namespace include: class, function, const ( Starting from php5.3 You can also use const to define constants outside of a class, but the difference between const and define is that the constants defined by define are global constants, and const defines constants within namespaces);
The simplest namespaces are used as follows:
Namespace A;function A () { return ' aaaaaaaaaaaaaaaaa '; } namespace B;function B () { return ' bbbbbbbbbbbbbbbbbbbbbb '; } Echo \a\a ();
Note: Before the first namespace definition cannot have any PHP output code, why is the first namespace? Because multiple namespaces can be defined in a file. The implication in the above example is that the element (function) in namespace A is used in namespace B;
Public space Concept: what is public space? Public spaces are code that we do not define namespaces, all in public spaces, if the elements of a public space are used in a namespace "\", such as: Echo \function ();