Android programmers learn PHP development (30)-ThinkPHP5.0 (2) namespace-PhpStorm

Source: Internet
Author: User
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.