Error message about disabling Notice in PHP

Source: Internet
Author: User
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


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


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


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.