PHP4 User manual: Constants _php Tutorials

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

  • 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.