How does PHP set the error reporting level?

Source: Internet
Author: User
In our program development, we often encounter program running errors. PHP will give different prompts based on the program error level. For example, what warnings, errors, and other errors can be set. if there are only some small errors, we can prevent them from being reported. This requires the setting of PHP error levels described in this chapter. In our program development, we often encounter program running errors. PHP will give different prompts based on the program error level. For example, what warnings, errors, and other errors can be set. if there are only some small errors, we can prevent them from being reported. This requires the setting of PHP error levels described in this chapter.

In PHP, there are two ways to set the error level:

First: After error_reporting is set in this mode, the web server will take effect permanently after it is restarted.

Take the xampp integrated software package as an example. open the configuration file php. ini and check the default value of Error Report level error_reporting, as shown below:

Error_reporting = E_ALL &~ E_DEPRECATED &~ E_STRICT

It indicates reporting all errors, except E_DEPRECATED and E_STRICT.

Modify it:

Error_reporting = E_ALL &~ E_NOTICE

This indicates reporting all errors, except for E_NOTICE. This is also the most common error reporting level. it does not report errors of the attention class (for example, using undefined variables.

Save and restart the web server.

Method 2: Use the error_reporting () function to set the error level. after setting the error level, the setting takes effect immediately. However, it is limited to the following areas after the error_reporting () function call in the current script.

The syntax of the error_reporting () function is as follows:

int error_reporting ([ int $level ] )

The level parameter specifies the error level. if it is not set, the current error level is returned. Below is the value of the level parameter.

Value Constant Description
1 E_ERROR Fatal error reported resulting in script termination
2 E_WARNING Report warning errors during running (the script will not stop running)
4 E_PARSE Report syntax parsing errors during compilation
8 E_NOTICE Reports a notification error. the script may generate an error.
16 E_CORE_ERROR A fatal error occurs during PHP initialization.
32 E_CORE_WARNING Warning during PHP initialization (non-fatal error ).
64 E_COMPILE_ERROR Fatal errors during compilation. This is like an E_ERROR generated by the Zend script engine.
128 E_COMPILE_WARNING Compile-time warning (non-fatal error ). This is like an E_WARNING warning generated by the Zend script engine.
256 E_USER_ERROR Custom warning messages. This is like an E_WARNING warning set by the programmer by using the PHP function trigger_error)
512 E_USER_WARNING Custom warning messages. This is like an E_WARNING warning set by the programmer by using the PHP function trigger_error)
1024 E_USER_NOTICE Custom warning messages. This is like an E_WARNING warning set by the programmer by using the PHP function trigger_error)
2048 E_STRICT Code Standardization warning. PHP is allowed to recommend how to modify the code to ensure the best interoperability forward compatibility.
4096 E_RECOVERABLE_ERROR A fatal error occurs when an ECS instance is started. This is like an E_ERROR, but it can be captured through user-defined processing (see set_error_handler ())
8191 E_ALL All errors and warnings (excluding E_STRICT) (E_STRICT will be part of E_ALL as of PHP 6.0)

The following code disables user-defined errors and warnings, performs some operations, and then restores the original error level:

 

A simple example is:

Error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE );

It indicates php errors, warnings, syntax errors, and prompts.

The above is how PHP sets the error level? For more information, see other related articles in the first PHP community!

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.