自定义 php 错误捕获代码

jopen 8年前

<?php  /**   * @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_shutdown_function('jd_fatal_error');    //注册错误处理函数  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:     //所有测错误类型都用下面的函数同意捕获       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 '<b>'.$type.':'.$message.' in '.$file.' on '.$line. ' line .</b><br />';  }    print_r(xx());    // print_r(debug_backtrace());  // print_r(debug_print_backtrace());



来自: http://my.oschina.net/anziguoer/blog/552551