Chapter 8. Constant Directory List Website Construction Server Script Class PHPPHP User Manual fancylanguage.constants.html#language.constants.syntax> Syntax Fixed constant
A constant is an identifier (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__). By default, a constant is case-sensitive. It is customary for constants to be capitalized.
The naming of constants in PHP is consistent with the naming of variable identifiers. A valid constant name starts with a letter or an underscore, and can be followed by alphanumeric characters, numbers, or underscores. Doing regular expression representation, it will be like this: [a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*
Note: A letter is a-z, A-Z, and from 127 to 255 (0x7f-0xff) ASCII characters.
The valid scope of constants 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 get the value of a constant simply by specifying its name. If you don't want variables, you don't need to think about $. You can also use the function constant() to read the value of a constant if you obtain the name of the constant dynamically. Use get_defined_constants() to get a list of all defined constants.
Note: Constants and (global) variables are in different namespaces. This means that values such as TRUE and $TRUE are usually different.
If you use an undefined constant, PHP will assume that the value of the constant with this name is itself. When this occurs, an error message will appear. If you want to know whether a constant has been set, use the defined() function.
Differences from variables:
Constants do not have a dollar sign ($) before them;
Constants must be defined, regardless of where they are accessed, regardless of the scope rules of the variable;
Constant is a quantity Once defined, it cannot be redefined or undefined;
Constant can just be a calculated quantity value.
Example 8-1. Define constants
http://www.bkjia.com/PHPjc/532347.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532347.htmlTechArticleChapter 8. Constant Directory List Website Construction Server Script Class PHPPHP User Manual fancylanguage.constants.html#language.constants .syntax>Syntax fixed constant A constant is a simple value...