Home  >  Article  >  Backend Development  >  Commonly used predefined constants and examples in PHP

Commonly used predefined constants and examples in PHP

伊谢尔伦
伊谢尔伦Original
2017-04-07 15:08:383205browse

PHPYou can use predefined constants to obtain information in PHP.

The commonly used predefined constants in PHP are as follows:

##Constant nameDescription##__FILE____LINE__PHP_OS PHP_VERSIONTRUEFALSENULLE_ERRORE_WARNING
The default constant is the PHP program file name
The default constant is the number of PHP program lines
Built-in constants refer to the name of the operating system that executes the PHP parser
Built-in constants refer to the version of the PHP program
The constant is a true value
The constant is a false value
A null value
Error, causing the php script to terminate
Warning will not cause the php script to terminate
E_PARSE Parse errors, reported by the program parser
E_NOTICE Non-critical errors, such as variables not initialized

Note: The "" in FILE and LINE are two underscores, not one "_".

Description: The predefined constants starting with E_ are the error debugging part of PHP.


PHP predefined constant example:

# #There is no difference in usage between predefined constants and user-defined constants. The following uses predefined constants to output information in PHP.

PHP程序当前行数:".LINE;
    echo "
当前PHP程序的版本:".PHP_VERSION; echo "
当前操作系统:".PHP_OS; ?>

Output results similar to the following:

PHP程序当前文件路径名:D:\phpStudy\www\index.php
PHP程序当前行数:3
当前PHP程序的版本:5.6.27
当前操作系统:WINNT

Note: Depending on the operating system and software version used by each user, the results may not be the same.


The above is the detailed content of Commonly used predefined constants and examples in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn