: 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.