Php namespace usage summary-php Tutorial

Source: Internet
Author: User
The php namespace usage summary can be used from php5.3. the namespace is used to prevent repeated namespace elements. Namespace elements include: class, function, and const (you can also use const to define constants outside the class starting with php5.3, but the difference between const and define is: the constant defined by define is a global constant, while the const defines a constant in the namespace );

The simplest namespace is as follows:

Namespace a; function a () {return 'aaaaaaaaaaaaaaaaa';} namespace B; function B () {return 'bbbbbbbbbbbbbbbbbbbbbb';} echo \ ();

Note: no php output code is available before the first namespace definition. why is it the first namespace? Because multiple namespaces can be defined in a file. In the preceding example, the elements (functions) in namespace a are used in namespace B );

Public space concept: what is public space? Public space is the code of the undefined namespace. it is all in public space. If an element that uses a public space in a namespace needs to use "\", for example, echo \ function ();

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.