PHP Magic Variables and namespaces

Source: Internet
Author: User

Magic variables:

PHP provides a large number of predefined constants to any script it runs.

However, many constants are defined by different extensions, and are only present when the extensions are loaded, either dynamically after loading, or they are included at compile time.

There are eight magic constants whose values change as they change position in the code.

For example, the value of __line__ depends on the row it is in the script to determine. These special constants are case-insensitive

As follows:

Namespaces:

PHP namespaces (namespace) are added in PHP 5.3, and if you learn C # and Java, that namespace is nothing new. However, in PHP there is a very important meaning.

The PHP namespace resolves the following two types of problems:

  1. User-written code conflicts with the name of a class/function/constant or third-party class/function/constant inside PHP.
  2. Creates an alias (or short) name for a very long identifier name (usually defined to alleviate the first type of problem), improving the readability of the source code.

PHP Magic Variables and namespaces

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.