The following tutorial column developed bythinkphpwill analyze the namespace of ThinkPHP for everyone. I hope it will be helpful to friends in need!
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 wordsC
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 name of its nearest namespacegetName()
d) Qualified name:beijinggetName()
Relative method
Locate through the nearest namespacebeijinggetName()
: As in the example below, he will think thatbeijinggetName()
is in the current directory, so Will finddalianbeijinggetName()
. At this time, an error will be reported because it cannot be found! !
e) Fully qualified name:beijinggetName()
Get specific elements directly in the specified namespace
f) Namespace targets: functions, class names, and constants Its function is to collectively refer to these three elements in the namespace.
The operation examples are as follows:
##Related recommendations: "The above is the detailed content of Parse ThinkPHP namespace. For more information, please follow other related articles on the PHP Chinese website!