PHP error_restore_error_handler() 函数
PHP Error 和 Logging 函数
定义和用法
restore_error_handler() 函数恢复之前的错误处理程序,该程序是由 set_error_handler() 函数改变的。
该函数永远返回 true。
语法
restore_error_handler()
提示和注释
提示:之前的错误处理程序可能是在错误处理程序或用户自定义函数中构建的。
例子
<?php
//custom error handler function
function customError($errno, $errstr, $errfile, $errline)
{
echo "<b>Custom error:</b> [$errno] $errstr<br />";
echo " Error on line $errline in $errfile<br />";
}
//set user-defined error handler
set_error_handler("customError");
$test=2;
//trigger error
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
//restore built-in error handler
restore_error_handler
//trigger error again
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
?>
//custom error handler function
function customError($errno, $errstr, $errfile, $errline)
{
echo "<b>Custom error:</b> [$errno] $errstr<br />";
echo " Error on line $errline in $errfile<br />";
}
//set user-defined error handler
set_error_handler("customError");
$test=2;
//trigger error
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
//restore built-in error handler
restore_error_handler
//trigger error again
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
?>
输出:
Custom error: [1024] A custom error has been triggered
Error on line 14 in C:\yige.org\test.php
Notice: A custom error has been triggered in
C:\yige.org\test.php on line 21
Error on line 14 in C:\yige.org\test.php
Notice: A custom error has been triggered in
C:\yige.org\test.php on line 21
PHP Error 和 Logging 函数