Home >Backend Development >PHP Tutorial >Custom php error catching code, register_shutdown_function(), set_error_handler(

Custom php error catching code, register_shutdown_function(), set_error_handler(

WBOY
WBOYOriginal
2016-07-25 08:45:571644browse
Customized php error catching code, register_shutdown_function(), set_error_handler()
  1. /**
  2. * @Author: yangyulong
  3. * @Date: 2015-12-28 22:09:22
  4. * @Last Modified by: yangyulong
  5. * @Last Modified time: 2015-12-28 22:48:49
  6. */
  7. error_reporting(0);
  8. //Register error catching function
  9. register_shutdown_function('jd_fatal_error');
  10. //Register error handling function
  11. set_error_handler(' jd_error_handler');
  12. function jd_fatal_error(){
  13. if ($e = error_get_last()) {
  14. switch ($e['type']) {
  15. case E_ERROR:
  16. case E_PARSE:
  17. case E_CORE_ERROR:
  18. case E_COMPILE_ERROR:
  19. case E_USER_ERROR:
  20. //All test error types are captured using the following function
  21. jd_error_handler($e['type'], $e['message'], $e['file'], $e['line ']);
  22. break;
  23. }
  24. }
  25. }
  26. /**
  27. * 捕获错误的函数
  28. *
  29. * @method jd_error_handler
  30. *
  31. * @param [type] $type [description]
  32. * @param [type] $message [description]
  33. * @param [type] $file [description]
  34. * @param [type] $line [description]
  35. *
  36. * @return [type] [description]
  37. */
  38. function jd_error_handler($type, $message, $file, $line){
  39. echo ''.$ type.':'.$message.' in '.$file.' on '.$line. ' line .
    ';
  40. }
  41. print_r(xx());
  42. // print_r(debug_backtrace());
  43. // print_r(debug_print_backtrace());
Copy code
Customize, php, register


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn