分类:
2005-12-21 10:06:38
// set the error reporting level for this script
error_reporting(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
switch ($errno) {
case E_USER_ERROR:
echo "严重错误!$errstr[$errno] in $errfile $errline!";
break;
case E_USER_WARNING:
echo "严重警告!$errstr[$errno] in $errfile $errline!";
break;
case E_USER_NOTICE:
echo "通知!$errstr[$errno] in $errfile $errline!";
break;
default:
echo "Unkown error type: [$errno] $errstr
";
break;
}
}
// function to test the error handling
function generate_error($var) {
switch ($var) {
case "1": trigger_error("var 的值为:1", E_USER_ERROR);break;
case "2": trigger_error("var 的值为:2", E_USER_WARNING);break;
case "3": trigger_error("var 的值为:3", E_USER_NOTICE);break;
default : echo "值不为:1,2,3!";
break;
}
}
// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");
generate_error(1);
generate_error(2);
generate_error(44);
?>