PHP restore_error_handler() 函数
完整的 PHP Error 参考手册
定义和用法
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:webfoldertest.php
Notice: A custom error has been triggered in
C:webfoldertest.php on line 21
Error on line 14 in C:webfoldertest.php
Notice: A custom error has been triggered in
C:webfoldertest.php on line 21
完整的 PHP Error 参考手册
点我分享笔记