PHP, constants

Source: Internet
Author: User
Tags constant definition

1. Constant definition:

Constants can be understood as the amount of constant values. When a constant value is defined, it cannot be changed anywhere else in the script. A constant consists of an English letter, an underscore, and a number, but the number cannot appear as a first letter.

2. Define variables:

Use the Define () function in PHP to define constants, which are syntactically formatted as:

Define (string constant_name,mixed value,case_sensitive=true)

Constant_name: Constant Name,

Value: The values of the constants,

Case_sensitive: Specifies whether case sensitive, set true, is not sensitive.

3. Determine if a variable has been defined:

To determine if a variable is already defined, you can use the defined () function, which has the following syntax:

bool Defined (string constant_name);

The parameter consttant_name is the name of the variable to get, the success returns True, and the failure returns false.

4. Get the variable:

There are two ways to get the value of a variable:

The first is to use the constant name to get the value directly;

The second is to use the constant () function, the constant () function and the direct use of the constant name output is the same effect, but the function can be dynamically output different constants, in the use of more flexible and convenient.

Some pre-defined constants in 5.php:

_file_: Php program file name;

_line_: Number of PHP program lines;

php_version:php version of the program, such as 3.0.8_dev;

Php_os: The name of the operating system executing the PHP parser, such as window;

True: The constant is a truth value (true);

False: The value is a false value (FALSE);

NULL: a null value;

E_error: This constant refers to the nearest error;

E_warning: This constant refers to the nearest warning point;

E_parse: This variable refers to a potential problem with the parsing syntax;

E_notice: This constant is an unusual hint, but not necessarily an error place.

PHP, constants

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.