PHP4 User Manual: constant. Variable # language. constants. syntax fixed constant a constant is a simple value chapter 8th. constant Directory List website construction server script class \ phpphp user manual fancy1_age.constants.html # language. constants. syntax> syntax fixed constant
A constant is the identifier (name) of a simple value ). As the name, this value cannot be changed during script execution (except for magic constants _ FILE _ and _ LINE ). By default, a constant is case sensitive. Normally, constants are capitalized.
In PHP, the constant name is the same as the variable identifier name. A valid constant name starts with a letter or underline, followed by a letter, number, or underline. Do a regular expression to indicate that it would be like this: [a-zA-Z_x7f-xff] [a-zA-Z0-9_x7f-xff] *
Note: a letter is a-z, A-Z, and ASCII characters from 127 to 255 (0x7f-0xff.
The valid range of a constant is global. Syntax
You can use the define () function to define a constant. After a constant is defined, it cannot be changed or deleted.
Only these types of data (boolean, integer, double and string) can be included in constants.
You can simply get the value of a constant by specifying its name. You don't need to consider $. You can also use the constant () function to read the value of a constant. Use get_defined_constants () to obtain a list of all defined constants.
Note: constants and (global) variables are in different namespaces. This means that, for example, TRUE and $ TRUE are usually different.
If you use an undefined constant, PHP assumes that the constant value of this name is its own. When this happens, an error message will appear. If you want to know whether a constant has been set, use the defined () function.
Differences with variables:
Constants do not have dollar signs ($) before them );
Constants must be defined, and the range rules of variables are not taken into account wherever they are accessed;
The constant quantity cannot be redefined or reversed;
A constant can only be a calculated value.
Example 8-1. define a constant
Constant. constant Directory List website construction server script class \ phpphp user manual fancy1_age.constants.html # language. constants. syntax> syntax fixed constant a constant is a simple value...