Home  >  Article  >  Backend Development  >  Usage and examples of php error_reporting() function

Usage and examples of php error_reporting() function

怪我咯
怪我咯Original
2017-07-10 14:32:571033browse

error_reporting() FunctionKneel down and tell you what kind of PHP error should be reported. This function 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 current error reporting level.

Syntax

error_reporting(level);
Parameters Description
level

Optional. Specifies the new error_reporting level. Can be a bitmask or a named constant.

Note: It is strongly recommended to use named constants to ensure compatibility with future versions. Due to the addition of error levels and the increase in the integervalue range, older integer-based error levels will not always behave as expected.

The available error level constants and their actual meanings are described in predefined constants.

Example:
Any number of the above options can be connected with "OR" (using OR or |), so that all required options can be reported Wrong level.
For example, the following code turns off user-defined errors and warnings, performs certain operations, and then returns to the original error level:

<?php
//禁用错误报告
error_reporting(0);
 
//报告运行时错误
error_reporting(E_ERROR | E_WARNING | E_PARSE);
 
//报告所有错误
error_reporting(E_ALL);
?>

The above is the detailed content of Usage and examples of php error_reporting() function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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