Customized php error catching code, register_shutdown_function(), set_error_handler()
- /**
- * @Author: yangyulong
- * @Date: 2015-12-28 22:09:22
- * @Last Modified by: yangyulong
- * @Last Modified time: 2015-12-28 22:48:49
- */
- error_reporting(0);
- //Register error catching function
- register_shutdown_function('jd_fatal_error');
- //Register error handling function
- set_error_handler(' jd_error_handler');
- function jd_fatal_error(){
- if ($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:
- //All test error types are captured using the following function
- jd_error_handler($e['type'], $e['message'], $e['file'], $e['line ']);
- break;
- }
- }
- }
- /**
- * 捕获错误的函数
- *
- * @method jd_error_handler
- *
- * @param [type] $type [description]
- * @param [type] $message [description]
- * @param [type] $file [description]
- * @param [type] $line [description]
- *
- * @return [type] [description]
- */
- function jd_error_handler($type, $message, $file, $line){
- echo ''.$ type.':'.$message.' in '.$file.' on '.$line. ' line .
';
- }
-
- print_r(xx());
-
- // print_r(debug_backtrace());
- // print_r(debug_print_backtrace());
Copy code
|