PHP namespace usage instance analysis, namespace

Source: Internet
Author: User

PHP namespace usage instance analysis, namespace

This example describes the usage of the PHP namespace. We will share this with you for your reference. The details are as follows:

Namespace (namespace) is equivalent to a function and a class. It divides a region so that the same page can have the same require class and use the same name function.
: Rarely used in projects

Name. php:

<? Php // use the namespace me \ mine compound name for naming; class me {public function _ construct () {echo 'name '. '<br>';} public function name () {echo 'I use space '. '<br>' ;}}// $ me = new me (); function me () {echo 'is me '. '<br> ';}

Common. php:

<? Phpclass me {public function _ construct () {echo 'no namespace'. '<br> ';}}
<? Php // the alias use me \ mine as I; require is recommended '. /name. php '; require '. /common. php'; $ me = new I \ me (); $ me-> name (); I \ me (); $ com = new me ();

Run the following command:

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.