8th chapter. Constants Directory List Web site construction Server script Class \phpphp user manual fancylanguage.constants.html#language.constants.syntax> syntax fixed constant
A constant is an identifier (first name) of a simple value. As a name, this value cannot be changed during the execution of the script (except for the Magic constants __file__ and __line__). The default one constant is case-sensitive. Customary constants are usually capitalized.
The name of the constant in PHP is consistent with the name of the variable identifier. A valid constant name begins with a letter or underscore, and can be followed by a letter symbol, a number, or an underscore. To do the regular expression, it will be this: [a-za-z_x7f-xff][a-za-z0-9_x7f-xff]*
Note: One letter is a-Z, A-Z, and ASCII characters from 127 to 255 (0X7F-0XFF).
The valid range of constants is global. Grammar
You can use the Define () function to define a constant. Once a volume 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 specify its name to get the value of a constant. Do not want variables, you do not need to consider bringing $. You can also use the function constant () to read a constant value if you are dynamically getting the name of the constant. Use Get_defined_constants () to get a list of all defined constants.
Note: Constants and (global) variables are in different namespaces. This means that as true and $ true are usually different.
If you use an undefined constant, PHP will assume that the value of the name's constant is itself. When this occurs, an error message will appear. If you want to know if a constant is set, use the defined () function.
Different points from the variables:
Constants do not have a dollar symbol ($) before them;
Constants must be defined, regardless of where they are accessed, without regard to the scope rules of variables;
A constant quantity is defined so that it cannot be redefined or reversed;
A constant can be just a calculated quantity value.
Example 8-1. Defining constants
http://www.bkjia.com/PHPjc/532347.html www.bkjia.com true http://www.bkjia.com/PHPjc/532347.html techarticle 8th. Constants Directory List Web site construction Server script Class \phpphp user manual fancylanguage.constants.html#language.constants.syntax> syntax fixed constant A constant is a simple value ...