Notes for php learning NOTE _ 4 _ constants and magic constants

Source: Internet
Author: User
: This article mainly introduces the things you need to pay attention to when learning the _ 4_constant and the magic constant in php. if you are interested in the PHP Tutorial, please refer to it. In php, constants correspond to Variables. constants are subsystem constants, framework constants, and custom constants.
You can use the following to define constants:


  

Note:
1. use it directly without the '$' symbol;
2. constants can be defined and used anywhere;
3. you can use the constant name or the constant (constant name) function to obtain the constant value;
4. get_defined_constants (); you can get all defined constants;

Magic constants: they are added by different extension libraries. Common magic constants include:

Name Description
__LINE__ The current row number in the file.
__DIR__ Directory of the current file.
__FILE__ The complete file path and file name. If it is used in a include file, the include file name is returned. Since php 4.0.2, FILE always contains an absolute path, while previous versions sometimes contain a relative path.
__FUNCTION__ Function name (new php 4.3.0 ). Starting from php 5, this constant returns the name (case sensitive) when the function is defined ). In php 4, the value is always lowercase letters.
__CLASS__ Class name (new php 4.3.0 ). Starting from php 5, this constant returns the name (case sensitive) when the class is defined ). In php 4, the value is always lowercase letters.
__METHOD__ Class method name (new php 5.0.0 ). Returns the name (case sensitive) when the method is defined ).
__NAMESPACE__ Name of the current namespace (case sensitive ). This constant is defined during compilation (new in PHP 5.3.0)

Copyright Disclaimer: This article is an original article, and the Reprinted article must indicate the source. the viewpoint of this article only represents the current opinion, which must be insufficient. thank you very much for your attention!

The above describes the things that need to be paid attention to when learning the _ 4_constant and the magic constant in php, including some content. I hope to help anyone who is interested in the PHP Tutorial.

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.