Home  >  Article  >  Backend Development  >  How to use php error_reporting function

How to use php error_reporting function

青灯夜游
青灯夜游Original
2019-05-27 09:48:083095browse

The error_reporting() function is used to set the error reporting level of the current script and specify what kind of PHP errors are reported. The syntax is error_reporting(report_level), which returns the old error reporting level.

How to use php error_reporting function

How to use the php error_reporting() function?

The error_reporting() function sets the error reporting level of the current script and specifies what kind of PHP errors are reported.

This function can set 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 level argument is not set, error_reporting() simply returns the current error reporting level.

Syntax

error_reporting(report_level)

Parameters:

● 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 range of integer values, 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.

Reporting level

How to use php error_reporting function

Return value: Return the old error reporting (error_reporting) level, or in Returns the current level when the level argument is not given.

Let’s take a look at how to use the php error_reporting() function through an example.

Example:Specify different error level reporting

<?php
 // 关闭错误报告
 error_reporting(0);
 // 报告 runtime 错误
 error_reporting(E_ERROR | E_WARNING | E_PARSE);
 // 报告所有错误
 error_reporting(E_ALL);
 // 等同 error_reporting(E_ALL);
 ini_set("error_reporting", E_ALL);
 // 报告 E_NOTICE 之外的所有错误
 error_reporting(E_ALL & ~E_NOTICE);
?>

The above is the detailed content of How to use 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