エラーハンドラ


/ Published in: PHP
Save to your folder(s)

適当エラーハンドラ


Copy this code and paste it in your HTML
  1. /**
  2.  * 開発時につかうエラーハンドラ
  3.  *
  4.  * E_USER_ERROR プログラムを終了するようなエラー(DB接続不能など)
  5.  * E_USER_WARNING 想定外の動作の警告(意図しない変数の上書きなど)
  6.  * E_USER_NOTICE エラーではないが、想定した動作をしているか確認できるためのデバッグ情報
  7.  *
  8.  * @return void
  9.  * @param PHP の set_error_handler() 関数のマニュアル参照
  10.  */
  11. function handle_error($err_no, $err_str, $err_file, $err_line)
  12. {
  13. global $config;
  14. if(preg_match('/' . $config['log_filter_ignore'] . '/', $err_str)) {
  15. return;
  16. }
  17.  
  18. $bc = debug_backtrace();
  19.  
  20. // バックトレースを表示
  21. $str = "<table>";
  22. foreach($bc as $b) {
  23. if(isset($b['args'][0])) {
  24. $mess = $b['args'][0];
  25. } else {
  26. $mess = '';
  27. }
  28.  
  29. if(preg_match('/validate/', $b['function'])) {
  30. continue;
  31. }
  32.  
  33. $str .= "<tr>";
  34. $str .= "<td>" . $b['file'] . '(' . $b['line'] . ') </td><td>' . $b['function'] . '</td><td>' . $mess . '</td>';
  35. $str .= "</tr>";
  36. }
  37. $str .= "</table>";
  38. print $str;
  39. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.