PHP predefined constant instance details

Source: Internet
Author: User
We can use the predefined constants of PHP to obtain information in PHP. for example, we can use the operating system of the current computer and the current PHP version information. What is the role of PHP predefined constants?

We can use the predefined constants of PHP to obtain information in PHP. for example, we can use the operating system of the current computer and the current PHP version information.

Some predefined constants commonly used by PHP are as follows:

Constant name Function
_ FILE __ Default constant, PHP program file name
_ LINE __ Default constant, number of PHP programs
PHP_VERSION Built-in constants, PHP program version, such as 3.0.8 _ dev
PHP_ OS Built-in constant, the name of the operating system that executes the PHP parser, such as Windows
TRUE This constant is a true value (true)
FALSE This constant is a false value)
NULL A null value
E_ERROR This constant indicates the most recent error.
E_WARNING This constant refers to the nearest warning.
E_PARSE This constant indicates a potential problem with the parsing syntax.
E_NOTICE This constant is an unusual prompt, but not necessarily an error.

 Current number of rows: ". _ LINE __; echo"
Current PHP version: ". PHP_VERSION; echo"
Current operating system: ". PHP_ OS;?>

Instance details:

The usage of predefined constants is no different from that of custom constants.

In the preceding example, the PHP predefined constant _ FILE _ is used to obtain the path of the current php file. The PHP predefined constant _ LINE _ gets the number of lines of the program; the PHP_VERSION predefined constant gets the current PHP version, and the PHP_ OS predefined constant gets the current operating system.

The code execution result is as follows:

Because each user uses different operating systems and system versions, the obtained results may be different, which is obtained based on the actual situation of each user.

I learned about PHP constants. in the next section, I will show you the "variables" in PHP"

Related video tutorial recommendations: php1.cn solitary nine cheap (4)-php Video Tutorial: pre-defined variables and constants

The above is a detailed description of PHP predefined constant instances. For more information, see other related articles in the first PHP community!

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.