PHP4 User Manual: constant _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.