Home > Backend Development > PHP Tutorial > PHP4 User Manual: Constants_PHP Tutorial

PHP4 User Manual: Constants_PHP Tutorial

WBOY
Release: 2016-07-13 17:22:30
Original
971 people have browsed it

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

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template