PHP4 User Manual: Constant

zhaozj2021-02-08  233

Chapter 8. Constant

Directory list

grammar

Fixed constant

A constant is an identifier (name) of a simple value. As a name, this value is not changed during the execution of the script (except for magic constant __file__ and __line__). A default is sensitive to case sensitive. Customary constants are usually capitalized.

The naming of the constant in PHP is consistent with the naming of the variable identifier. An effective constant name begins with letters or underscores, which can be alphabetic symbols, numbers, or underscores. Do a regular expression, 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 ASCII characters from 127 to 255 (0x7F-0xFF).

The effective range of constants is global.

grammar

You can define a constant using the define () function. After one amount of constant is defined, it cannot be changed or deleted.

It is only these types of data (Boolean, Integer, Double and String) can be included in a constant.

You can get a constant value by specifying its name. Don't want to variables, you don't need to consider bring $. You can also use the function constant () to read a constant value if you are a dynamic 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 RRUE and $ TRUE are usually different.

If you use undefined constants, PHP will assume that the value of the constant of this name is itself. When this occurs, an error message will appear. If you want to know if a constant has been set, use the defined () function.

Different points with variables:

There is no US dollar ($) before they; constants must be defined, no matter where access does not consider the range rules of variables; constants can not be redefined or reversible; constants can be simply calculated value.

Example 8-1. Define constants

Define ("Constant", "Hello World.");

Echo constant; // Output "Hello World."

Echo constant; // Output "Constant" and Issues a Notice.

?>

转载请注明原文地址:https://www.9cbs.com/read-3438.html

New Post(0)