Home > PHP Framework > ThinkPHP > Detailed explanation of namespace in THINKPHP

Detailed explanation of namespace in THINKPHP

Release: 2020-05-16 09:25:45
forward
2941 people have browsed it

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:

Detailed explanation of namespace in THINKPHP

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template