function _e($msg,$type=''){
static $i=0;
$i++;
$error['msg'] = $msg;
$error['type'] = $type;
$GLOBALS[ERROR_STACK_NAME][$i] = $error;
return ERROR_STACK_NAME.$i;
}
function onError($errNo, $errMsg, $file, $line, $errcontext) {
$errorlevels = array(
2048 => 'Warning',
2048 => 'Notice',
1024 => 'Warning',
1024 => 'Notice',
512 => 'Warning',
256 => 'Error',
128 => 'Warning',
64 => 'Error',
32 => 'Warning',
16 => 'Error',
8 => 'Notice',
4 => 'Error',
2 => 'Warning',
1 => 'Error');
$t = error_reporting();
if (!($errNo & error_reporting())) {
return;
}
$errType = $errNo;
if(strpos($errMsg,ERROR_STACK_NAME)==0){
$i = substr($errMsg,strlen(ERROR_STACK_NAME));
if(isset($GLOBALS[ERROR_STACK_NAME][$i])){
$error = $GLOBALS[ERROR_STACK_NAME][$i];
$errMsg = $error['msg'];
$errType = $error['type'];
}
}
$errMsg = nl2br($errMsg);
if($errType=='smarty'){
$errType = '模版系统错误';
}elseif ($errType=='sql'){
$errType = '数据库操作错误';
}else{
$errType = "PHP错误[$errType]";
}
$title = '系统错误';
$msg = "
<strong>错误类型:</strong><blockquote>$errType</blockquote>
<strong>错误位置:</strong><blockquote>$file 第 $line 行</blockquote>
<strong>错误信息:</strong><blockquote>$errMsg</blockquote>
";
echo $msg;flush();
exit();
}
function shutdown_function(){
$errorlevels = array(
2048 => 'Warning',
2048 => 'Notice',
1024 => 'Warning',
1024 => 'Notice',
512 => 'Warning',
256 => 'Error',
128 => 'Warning',
64 => 'Error',
32 => 'Warning',
16 => 'Error',
8 => 'Notice',
4 => 'Error',
2 => 'Warning',
1 => 'Error');
$error = error_get_last();
if($error){
echo '</tr></table></div></div></div></iframe><div style="clear:both"></div><div style=" background-color:#FFBB00"><pre>';
echo '最后一个错误:';
$error ['type']= $errorlevels[$error ['type']];
print_r($error );
debug_print_backtrace();
echo '</pre></div>';
}else{
echo '本页面无错误!';
}
}
register_shutdown_function('shutdown_function');#定义最后一个错误捕获
define('ERROR_STACK_NAME', 'ERROR_STACK');
set_error_handler('onError');#定义错误处理函数
error_reporting(9);