How to set the error reporting level of the error_reporting() function in PHP

怪我咯
Release: 2023-03-13 12:08:01
Original
1179 people have browsed it

error_reporting() function tells you what PHP errors should be reported. Thisfunction enables setting the error_reporting directive at runtime.

PHP has many error levels. Use this function to set the level when the script is running. If the optional parameter level is not set, error_reporting() will only return the currenterror reportinglevel.

Error reporting level: Specifies under what circumstances errors in the script code (errors here are generalized errors, including E_NOTICE attention, E_WARNING warnings, E_ERROR fatal errors, etc.) will be output in the form of an error report . Method to set the error reporting level:

  1. Modify PHP'sconfiguration filephp.ini After setting error_reporting in this way, restart the web server and it will take effect permanently. Taking the xampp integrated software package as an example, open the configuration file php.ini and check the default value of error reporting level error_reporting, as follows: error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT means reporting all errors, except for E_DEPRECATED and E_STRICT. kind. Modify it to: error_reporting=E_ALL & ~E_NOTICE means reporting all errors except E_NOTICE. This is also the most commonly used error reporting level. It will not report errors of attention type (such as using undefined variables). Save and take effect after restarting the web server.

  2. Use the error_reporting() functionAfter setting in this way, it can take effect immediately. But only in the area after the error_reporting() function call in the current script. int error_reporting ([ int $level ] ) The parameter can be an integer or the correspondingconstantidentifier. It is recommended to use the constant form. The return value is the value (integer value) of the error reporting level in effect at the current location.

  3. The following are some error reporting levels:

    1. E_ERROR reporting causes the script to terminate Fatal errors during operation

    2 .E_WARNING reports warning errors during operation (the script will not terminate the operation)

    4. E_PARSE reports compilation Syntax parsing errors

    8 .E_NOTICE reports notification errors, the script may generate errors

    32767 E_ALL reports all possible errors Error (different PHP versions, the value of the constant E_ALL may also be different)

    error_reporting(E_ALL ^ E_NOTICE); // Except E_NOTICE, report all errors

    error_reporting(E_ERROR); // Only report fatal errors

echo error_reporting(E_ERROR | E_WARNING | E_NOTICE); // Only report E_ERROR, E_WARNING and E_NOTICE three errors. Excellent employment reminder: The default value ofdisplay_errorsin the configuration file php.ini is On, which means error prompts are displayed. If set to Off, all will be closed. error message.

The above is the detailed content of How to set the error reporting level of the error_reporting() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!