• 技术文章 >后端开发 >php教程

    自定义 php 错误捕获代码, register_shutdown_function(), set_error_handler(

    2016-07-25 08:45:57原创878
    自定义 php 错误捕获代码, 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. //注册错误捕捉函数
    9. register_shutdown_function('jd_fatal_error');
    10. //注册错误处理函数
    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. //所有测错误类型都用下面的函数同意捕获
    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());
    复制代码
    自定义, php, register


    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:自定义 php 错误捕获代码, register_shutdown_function() set_error_hand
    上一篇:php中的标量数据是什么 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • 一文详解PHP用流方式实现下载文件(附代码示例)• PHP反序列化入门总结(小白必看)• PHP原生类的总结分享• 聊聊PHP escapeshellarg函数使用的中文问题• 分享PHP函数使用小工具(附代码示例)
    1/1

    PHP中文网