This article introduces some practices for disabling notice errors in php, but I have to say whether a large number of notice-level errors in the program code will cause PHP performance degradation when the error prompt is turned off.
This article introduces some practices for disabling notice errors in php, but I have to say whether a large number of notice-level errors in the program code will cause PHP performance degradation when the error prompt is turned off.
PHP Notice: Undefined variable, PHP Notice: Undefined index
Let's take a look. you can use undefined variables directly, but PHP is not as strict as C ++. this feature is often used during programming. The default setting of PHP is to display these prompts, which causes the page to fail to display normally. the code is as follows:
- // Error_reporting (E_ALL );
- Error_reporting (E_ALL | ~ E_NOTICE); // display all error messages except E_NOTICE
The first is to show all errors, and the second is to show all errors without warning. we only need to add // before the second line and remove the // before the first line.
Appendix: detailed explanation of various error reports,The code is as follows:
Error_reporting (0); // disable error reporting
Error_reporting (E_ALL ^ E_NOTICE); // display all error messages except E_NOTICE
Error_reporting (E_ALL ^ E_WARNING ^ E_NOTICE); // display all error messages except E_WARNING E_NOTICE
Error_reporting (E_ERROR | E_WARNING | E_PARSE); // displays a running error.
Error_reporting (E_ALL ^ E_NOTICE); // displays a running error, which is the same as the preceding one.
Error_reporting (E_ALL); // display all errors
The code is as follows:
- If (! $ ){
- Error_reporting (0 );
- Ob_start ('OB _ gzhandler ');
- } Else {
- Error_reporting (E_ALL ^ E_NOTICE );
- }
Disable modification in php. ini
1. modify the configuration file of php. ini in the server of the space provider: change error_reporting in the php. ini file to error_reporting = E_ALL &~ E_NOTICE: If you are a fixed U. S. Space user and cannot operate the php. ini file, you can use the following method.
2. add the following code to the page where you want to disable the notice error prompt.
Error_reporting (E_ALL ^ E_NOTICE );
Note that:Disabling PHP error output does not disable php kernel-based error handling. if a large number of Notice-level errors exist in the code, the php program performance will be reduced. Therefore, during development, we still need to open the error level to E_ALL, so we can carefully process every unreasonable code.