Home > Article > Backend Development > How to display error level in php
How to display the error level in php: first find and open the php.ini configuration file; then set the value of the "error_reporting" item to "E_ALL", set the value of the "display_errors" item to "On"; finally save Just file.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Warning: Never use in production environment Show any error messages!
Display errors (display_errors) and error reporting (error_reporting) are two different things. When an error occurs in a PHP script, you can choose whether to report the error (record it in the error log) according to the settings. If display_errors is turned on in the settings, the error message will be printed to the screen at the same time.
ini_set() function
For PHP , various instructions can be set through the php.ini
file. But sometimes you need to set instructions when the script is running, then you need the ini_set()
function.
string ini_set ( string $varname , string $newvalue )
Set the value of the specified configuration option. This option will retain its new value while the script is running, and will be restored when the script ends.
For example:
ini_set('error_reporting', E_ALL); ini_set('display_errors', 'on');
error_reporting() function
error_reporting()
The function can be run When setting the error_reporting directive. PHP has many error levels. Use this function to set the level when the script is running. If the optional argument is not set, error_reporting() returns the current error reporting level.
The default value for PHP7.2 is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
.
It is recommended to enable E_NOTICE during the development stage to display more possible errors.
<?php // 关闭所有PHP错误报告,相当于 ini_set('error_reporting', 0); error_reporting(0); error_reporting(E_ERROR | E_WARNING | E_PARSE); // 报告 E_NOTICE (报告未初始化的变量或捕获变量名的错误拼写) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // 除了 E_NOTICE,报告其他所有错误 error_reporting(E_ALL ^ E_NOTICE); // 报告所有 PHP 错误 (参见 changelog) error_reporting(E_ALL); // 报告所有 PHP 错误 error_reporting(-1); // 和 error_reporting(E_ALL); 一样 ini_set('error_reporting', E_ALL);
error_reporting = E_ALL # 报告所有错误 display_errors = On # 显示错误
The official website defines all errors Constants, commonly used ones are:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to display error level in php. For more information, please follow other related articles on the PHP Chinese website!