Home > Article > Backend Development > How to use PHP error reporting function error_reporting()?
In PHP, the error reporting function error_reporting() is used to specify what kind of PHP errors should be reported, the syntax is "error_reporting(level)"; use this function to set the error level when the script is running, if not set it is optional parameter level, only the current error reporting level is returned.
Recommended: "PHP Video Tutorial"
error_reporting() function specifies what kind of PHP errors you should report .
The error_reporting() 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 parameter level is not set, error_reporting() will only return the current error reporting level.
Syntax
error_reporting(report_level)
Parameters:
report_level: Optional. Specifies the error reporting level for the current script. Both value numbers and constant names are accepted, however, for compatibility with future PHP versions, it is recommended to use constant names.
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.
Reporting level
Return value: Return the old error_reporting level, or the level parameter is not given Returns the current level when exiting.
Example: Specify different error level reports
<?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); ?>
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of How to use PHP error reporting function error_reporting()?. For more information, please follow other related articles on the PHP Chinese website!