Error message about disabling Notice in PHP

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

  1. // Error_reporting (E_ALL );
  2. 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:

  1. If (! $ ){
  2. Error_reporting (0 );
  3. Ob_start ('OB _ gzhandler ');
  4. } Else {
  5. Error_reporting (E_ALL ^ E_NOTICE );
  6. }

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.

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: info-contact@alibabacloud.com 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.