Copy code The code is as follows:
//Disable error output
error_reporting(0 );
//Set error handler
set_error_handler('errorHandler');
register_shutdown_function('fatalErrorHandler');
class Test{
public function index(){
/ /A warning error occurs here, start errorHandler
echo $undefinedVarible;
}
}
function errorHandler($errno,$errstr,$errfile,$errline){
$arr = array (
'['.date('Y-m-d h-i-s').']',
'http://www.baidu.com',
'|',
$errstr,
$errfile,
'line:'.$errline,
);
//Write error log
//Format: Time uri | Error message file location line number
error_log(implode(' ',$arr)."rn",3,'./test.txt','extra');
echo implode(' ',$arr)."rn";
}
//Capture fatalError
function fatalErrorHandler(){
$e = error_get_last();
switch($e['type']){
case E_ERROR:
case E_PARSE :
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
errorHandler($e['type'],$e['message'],$e['file'],$e ['line']);
break;
}
}
$test = new Test();
////A warning error occurred here and was captured by errorHandler
$test->index();
//A fatal error occurs and the script stops running and triggers fatalErrorHandler
$test = new Tesdt();
$test->index();
|
|
http://www.bkjia.com/PHPjc/736856.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736856.htmlTechArticleCopy the code as follows: ?php //Disable error output error_reporting(0); //Set the error handler set_error_handler ('errorHandler'); register_shutdown_function('fatalErrorHandler');...