Commonly used predefined constants and examples in PHP

伊谢尔伦
Release: 2023-03-07 11:28:01
Original
3352 people have browsed it

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
    echo "PHP程序当前文件路径名:".FILE;
    echo "<br >PHP程序当前行数:".LINE;
    echo "<br >当前PHP程序的版本:".PHP_VERSION;
    echo "<br >当前操作系统:".PHP_OS;
?>
Copy after login

Output results similar to the following:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!