A constant used to learn PHP at the front end

Source: Internet
Author: User
Tags constant definition php define
: This article mainly introduces the constants used to learn PHP at the front end. For more information about PHP tutorials, see. Directory [1] constant definition [2] Custom constant [3] system constant [4] constant value [5] defined ()

Constant definition

Constants are similar to variables, but once defined, constants cannot be changed or undefined. Constants are mainly used to avoid repeated definitions, tamper with variable values, and improve code maintainability. A valid constant name starts with a character or underscore (the constant name has no $ symbol before it ). Generally, constants are all capitalized. Constants in PHP are divided into custom constants and system constants.

[Note] unlike variables, constants are automatically Global throughout the script.

Custom constant

The user-defined constant uses the define () function, which uses three parameters

[1] name of the first parameter definition constant

[2] The second parameter defines the constant value

[3] The third optional parameter specifies whether the constant name is case sensitive. the default value is false.

The syntax format of the define () function is:

bool define(string$constant_name, mixed$value[, $case_sensitive = true])

 "; Echo PI0; // 3.14?>

System constant

System constants are defined by PHP. common system constants include:

[1] _ FILE __: php program FILE name. Obtain the physical location of the current file on the server

[2] _ LINE __: number of PHP program files. Number of lines in the current code

[3] PHP_VERSION: version number of the current parser. You can know in advance whether the PHP code can be parsed by the PHP parser.

[4] PHP_ OS: name of the operating system for executing the current PHP version. Tell the server the name of the operating system used, and optimize the code based on the operating system

 ";echo__LINE__;//11echo "
";echoPHP_VERSION;//5.5.12echo "
";echoPHP_OS;//WINNTecho "
";?>

Constant value

You can use either the constant name or the constant () function to obtain a constant value.

Constant () function syntax format: mixed constant (string constant_name)

 

Defined () function

If the Constant is repeatedly defined, the PHP parser will issue a warning of "Constant XXX already defined", reminding that the Constant has been defined

The defined () function is used to determine whether a constant has been defined. Its syntax format is:

bool defined(string constants_name)

If yes, true is returned. otherwise, false is returned.

 

The above describes the constants used by the front-end to learn PHP, including some content. I hope that my friends who are interested in the PHP Tutorial will be helpful.

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.