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!