How to set the error_reporting error reporting level in PHP

Source: Internet
Author: User

Error Reporting Level: Specifies the circumstances under which the error in the script code (where the error is generalized, including e_notice attention, e_warning warning, e_error fatal error, etc.) is output in the form of an error report.

To set the error reporting level method:

1. Modify the PHP configuration file php.ini

After setting error_reporting in this way, restarting the Web server will take effect forever.

Take the XAMPP integration package as an example, open the profile php.ini and view the default values for error report level error_reporting as follows:

Error_reporting=e_all & ~e_deprecated & ~e_strict

It means to report all errors, but except e_deprecated and e_strict.

Modify it to:

Error_reporting=e_all & ~e_notice

It means to report all errors, but except E_notice. This is also the most commonly used error reporting level, and it does not report errors that note classes (such as those that use undefined variables).

Save and take effect after restarting the Web server.

2. Using the error_reporting () function

This mode can be applied immediately after it is set. But limited to the following area of the error_reporting () function call in the current script.

int error_reporting ([int  $level ])

The parameter can be an integer or a corresponding constant identifier, and it is recommended to use the form of a constant. The return value is the value of the error report level at the current position (integer value).

Some error reporting levels are listed below:

Value constant Description

1 E_error report A fatal error that causes the script to end running

2 e_warning Report Runtime warning class error (script does not terminate running)

4 E_parse Report compile-time syntax parsing error

8 E_NOTICE Report notification class error, script may produce error

32767 E_all Report all possible errors (different PHP versions, constant E_all values may also vary)

Error_reporting (e_all ^ e_notice); All errors are reported except for E_notice

Error_reporting (E_error); Only fatal errors are reported

echo error_reporting (E_error | e_warning |   E_notice); Only three errors are reported for E_error, E_warning, and E_notice

Note: The default value for Display_errors in profile php.ini is on, which indicates that an error is displayed, and if set to OFF, all error prompts are turned off.


How to set the error_reporting error reporting level in PHP

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.