PHP Namespace Usage Summary

Source: Internet
Author: User
Namespaces can be used starting from php5.3, and namespaces are used to prevent duplicate elements of namespaces. The elements of a namespace include: class, function, const ( Starting from php5.3 You can also use const to define constants outside of a class, but the difference between const and define is that the constants defined by define are global constants, and const defines constants within namespaces);

The simplest namespaces are used as follows:

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

Note: Before the first namespace definition cannot have any PHP output code, why is the first namespace? Because multiple namespaces can be defined in a file. The implication in the above example is that the element (function) in namespace A is used in namespace B;

Public space Concept: what is public space? Public spaces are code that we do not define namespaces, all in public spaces, if the elements of a public space are used in a namespace "\", such as: 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.