<?php
// ini_set('display_errors', 'on');
// error_reporting(E_ALL|E_STRICT);
error_reporting(0);
// 错误异常类 错误接管
class App{
public function __construct(){
$this->iserr();
}
public function iserr(){
set_exception_handler([$this,'ex']);
set_error_handler([$this,'err']);
//脚本运行结束前调用rsf
register_shutdown_function([$this,'rsf']);
}
public function rsf(){
$er = error_get_last();
if(in_array($er['type'],[1,4,16])){
$this->errorlog($er['type'],$er['message'],$er['file'],$er['line']);
}
}
/**
*异常接管
*/
public function ex($ex){
$msg = $ex->getMessage();
$type = $ex->getCode();
$file = $ex->getFile();
$line = $ex->getline();
// echo '类型:'.$type.'信息:'.$msg.' 位置:'.$file.' 错误行:'.$line;
$this->errorlog($type,$msg,$file,$line);
}
/**
*获取错误信息
*/
public function err($type,$msg,$file,$line){
// echo '类型:'.$type.'信息:'.$msg.' 位置:'.$file.' 错误行:'.$line;
$this->errorlog($type,$msg,$file,$line);
}
/**
*错误日志
*/
public function errorlog($type,$msg,$file,$line){
$errstr = date('Y-m-d H:i:s',time())."
";
$errstr .= '错误级别'.$type."
";
$errstr .= ' 错信息'.$msg."
";
$errstr .= ' 错误文件'.$file."
";
$errstr .= ' 错误行'.$line;
$errstr.='
';
error_log($errstr,3,'err.log');
}
}
new App();
// include ('err.php');
echo $s;
// echo $app->iserr();
// throw new Exception("Error Processing Request", 500);