Home > Article > PHP Framework > Detailed explanation of namespace in THINKPHP
We all know that since PHP syntax does not support the function overloading mechanism, what should we do if there are two methods with the same name in an application?
In the Yii framework, in order to avoid problems caused by name duplication, all classes have the word C in front of them, and the concept of namespace is introduced in ThinkPHP.
a) The namespace is a virtual definition space, not a real directory
b) The delimiters of the namespace are all backslashes\
c) Unqualified name : getName() Get the getName()
d) of its nearest namespace Qualified name: beijinggetName() Relative method
Locate beijinggetName() through the nearest namespace: as in the following example , he will think that beijinggetName() is in the current directory, so he will find dalianbeijinggetName(). At this time, an error will be reported because it cannot be found! !
e) Fully qualified name: beijinggetName() directly obtains the specific element in the specified namespace
f) The namespace targets: functions, class names, and constants. Their functions are in the namespace. These three types are collectively referred to as elements
The operation examples are as follows:
Recommended tutorial: "TP5"
The above is the detailed content of Detailed explanation of namespace in THINKPHP. For more information, please follow other related articles on the PHP Chinese website!