In a broad sense, namespace is a way to encapsulate things. This abstract concept can be seen in many places. For example, in the operating system, the directory is used to group related files, and the namespace uses the range access method.
*
Namespace
In a broad sense, namespace is a way to encapsulate things. This abstract concept can be seen in many places. For example, a directory in the operating system is used to group related files,
For files in the directory, it plays the role of the namespace. For example, the foo.txt file can be stored in the/home/greg directory and/home/other directory at the same time.
But there cannot be two foo.txt files in the same directory. In addition, when accessing the foo.txt file outside the/home/greg Directory, we must
Put the separator before the file name to get/home/greg/foo.txt. This principle is applied to the field of programming as a namespace concept.
Http://php.net/manual/zh/language.namespaces.php
*
ThinkPHP5 defines and automatically loads class library files using namespaces, effectively solving namespace conflicts between multiple modules and Composer class libraries, and implementing more
Efficient automatic loading of class libraries.
Http://www.kancloud.cn/manual/thinkphp5/118014
*
Function is applicable to namespaces.
Const applies to namespaces
Class applies to namespaces
Define is not applicable to namespaces.
*
Access method:
1. unrestricted name access
2. fully qualified name access method
3. specify the name Access Method (relative path)
';} // Define ('mn', 'iwanghang '); const MN = "iwanghang
"; Class Animals {public $ obj = 'cat
';}/*** Kj2, namespace 2 */namespace kj2; use kj1 \ Animals; function getmsg () {echo '100
';} // Define ('mn', 'iwanghang0'); const MN = "iwanghang0
";/*** Access Method: 1. unlimitedly named access method */getmsg ();/*** access method: 2. fully qualified name access method */\ kj1 \ getmsg (); \ kj2 \ getmsg (); echo \ kj1 \ MN; $ animal = new Animals (); echo $ animal-> obj;/*** access method: 3. specify the name access method * // echo kj1 \ getmsg (); // An error is reported, function kj2 \ kj1 \ getmsg () cannot find this function/*** access method: 3. specify the name access method */namespace kj3; echo kj4 \ getmsg (); // print the result: 789 namespace kj3 \ kj4; function getmsg () {echo '2017
';}
The above is the PHP development (30)-ThinkPHP5.0 (2) namespace-PhpStorm content for Android programmers. For more information, see PHP Chinese website (www.php1.cn )!