PHPnamespace namespace details

Source: Internet
Author: User
Here we will introduce the usage of the php Tutorial namespace and the namespace keyword. in this article, we will introduce the use of the use command and how php resolves the namespace name. Namespacebakbaba; func...

Here we will introduce the usage of the php Tutorial namespace and the namespace keyword. in this article, we will introduce the use of the use command and how php resolves the namespace name.

namespace bakbaba;function bab(){    echo "bi";}namespace kkk;function k1(){    echo "k1";}


Bakbababab (); // use another namespace in the kkk namespace. Note the preceding
Use bakbaba as B; // it is still in the kkk namespace, but the following method is correct when using an alias:
# Use bakbaba as B; // do not use a number before
Bbab (); // when using the namespace under the alias, there should be no number in front of it
K1 (); // no error is returned when this function is called, indicating that use does not affect the current namespace

< ?php   // application library 1   namespace applib1;   const myconst = 'applib1myconst';   function myfunction() {    return __function__;   }   class myclass {    static function whoami() {   eturn __method__;    }   }   ?>  lib2.php< ?php   // application library 2   namespace applib2;     const myconst = 'applib2myconst';     function myfunction() {    return __function__;   }     class myclass {    static function whoami() {   eturn __method__;    }   }   ?> 

Fortunately, this piece of code is found in the manual, so other namespace content in the manual can be ignored. you can directly look at the following code.

 

Address:

Reprinted at will, but please attach the article address :-)

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.