This article describes how to disable notice errors in php. However, when you disable the error prompt, will a large number of notice-level errors in the program code cause PHP performance degradation PHPNotice: Unde...
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 directly use undefined variables. However, PHP compilation is not as strict as C ++, which is often used in programming. The default setting of PHP is to display these prompts, which will cause 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 one is to show all the errors,
The second is to display all errors without warning,
We only need to add // in front of the second line and remove the // in front of the first line.
Appendix: Detailed error reports
Usage:
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 runtime error, which is the same as error_reporting (E_ALL ^ E_NOTICE. Error_reporting (E_ALL); // display all errors |
Instance
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 on the server of the space provider:
Change error_reporting in the php. ini file
Changed:
The code is as follows: |
|
Error_reporting = E_ALL &~ E_NOTICE |
If you are a user in a fixed U.S. Space and cannot operate the php. ini file, you can use the following method to implement
2. add the following code to the page where you want to disable the notice error prompt.
The code is as follows: |
|
/* Report all errors before T E_NOTICE */ 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.
Permanent link:
Reprint at will! Include the article address.