In PHP, variables correspond to constants, constants are system constants, frame constants, and custom constants.
Defining constants can use the following
define("MY_FIELD",123); echo MY_FIELD;// 输出123// 如果定义常量是一个变量$name = "TEST"; define($name,"456"); echo$name;// 输出TESTecho constant($name);//输出真正的变量值456?>
Note the point:
1. Use directly, without adding ' $ ' sign;
2. Constants can be defined and used anywhere;
3. You can use the constant name or the constant (constant name) function to get the value of the constant;
4.get_defined_constants (); Can get all the constants that have been defined;
Magic constants: added by different extension libraries, the usual magic constants are the following:
name |
Description |
__LINE__ |
The current line number in the file. |
__DIR__ |
The directory where the current file resides. |
__FILE__ |
The full path and file name of the file. If used in the include file, the include filename is returned. Since PHP 4.0.2, FILE always contains an absolute path, and the previous version sometimes contains a relative path. |
__FUNCTION__ |
The name of the function (PHP 4.3.0 new addition). From PHP 5 This constant returns the name (case-sensitive) when the function is defined. In PHP 4, this value is always in lowercase letters. |
__CLASS__ |
The name of the class (PHP 4.3.0 new addition). From PHP 5 This constant returns the name of the class when it is defined (case-sensitive). In PHP 4, this value is always in lowercase letters. |
__METHOD__ |
The method name of the class (PHP 5.0.0 new addition). Returns the name of the method when it is defined (case-sensitive). |
__NAMESPACE__ |
The name of the current namespace (case sensitive). This constant is defined at compile time (PHP 5.3.0 new) |
Copyright NOTICE: This article is the original article, reprint need to indicate the source, the article view only represents the view at that time, there must be insufficient, welcome to make bricks remind, thank you very much!
The above describes the PHP learning notes _4_ constants and magic constants need to pay attention to the points, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.