When PHP is running, different prompts will be given for errors of different severity.
eg: When $a is not declared, it is added directly, and the value is NULL. When adding, it is calculated as 0. However, it prompts NOTICE, that is, attention.
We are under development , for the standardization of the program, the error reporting level is adjusted to a higher NOTICE level and also reported, which helps us quickly locate errors and code specifications. However, after the product is launched and the website is operated, it is not appropriate to report so many Wrong.
1: This kind of error gives a bad impression to the customer
2: When reporting the error, report the absolute path of the website, such as D:\www\1015. This increases the risk of being attacked Risk
Therefore, after the website is online, the error reporting level should be lowered, reporting fewer errors or even not reporting at all.
Modify the error reporting level:
1: Modify the error_reporting option in php.ini
2: You can use the error_reporting() function in the php page to modify the
error level using a binary value To represent: 1111 1111 1111 111 from left to right, 1 on each bit represents an error level
fatal error
Fatal error: 0000 0000 0000 001 Turn on 1
warning
Warning error: 0000 0000 0000 010 Open 2 NOTICE
Warning: 0000 0000 0001 000 Open 8
eg:
all reported Out: error_reporting(11)
;
Do not report NOTICE: error_reporting(3)
;
Do not report any errors: error_reporting(0)
;
The system replaces the values of each level with system constants for us.
E_ERROR
1 E_WARNING
2
E_NOTICE
8
Report all errors: error_reporting(E_ALL)
;
Report all errors except NOTICE: error_reporting(E_ALL & ~ E_NOTICE)
;
In development, the error level is higher. In the online product, the error level is lower:
The code is as follows:
define('DEBUG',true); // 在开发时,声明一个DEBUG模式 if(defined('DEBUG')) { //检测到处于开发模式 error_reporting(E_ALL); } else { error_reporting(0); }
More related For questions, please visit the PHP Chinese website: PHP Video Tutorial
The above is the detailed content of How to set php error mode. For more information, please follow other related articles on the PHP Chinese website!