sebbu

error_handler.php

Jul 5th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2. function error_handler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext)
  3. {
  4.     var_dump($errno.':'.$errstr);
  5.     var_dump($errfile.':'.$errline);
  6.     //var_dump($errcontext);
  7.     //print "backtrace:\n";
  8.     $backtrace = debug_backtrace();
  9.     array_shift($backtrace);
  10.     foreach($backtrace as $i=>$l){
  11.         print @"[$i] in function <b>{$l['class']}{$l['type']}{$l['function']}</b>";
  12.         if($l['file']) print " in <b>{$l['file']}</b>";
  13.         if($l['line']) print " on line <b>{$l['line']}</b>";
  14.         print "<br/>\n";
  15.     }
  16.     return true;
  17. }
  18. function exception_handler(Throwable $ex)
  19. {
  20.     if(function_exists('fix_error')) {
  21.         $str=fix_error($ex);
  22.         if($str) return false;
  23.     }
  24.     //var_dump($ex);
  25.     $str=get_class($ex);
  26.     echo $str.' ';
  27.     $str=$ex->getCode().':'.$ex->getMessage();
  28.     if(!is_null($str)) echo $str."<br/>\r\n";
  29.     $str=$ex->
  30.     $str=$ex->getFile().':'.$ex->getLine();
  31.     if(!is_null($str)) echo 'on '.$str."<br/>\r\n";
  32.     $str=$ex->getPrevious();
  33.     if(!is_null($str)) echo $str."<br/>\r\n";
  34.     $tr=$ex->getTrace();
  35.     //var_dump($tr);die();
  36.     for($i=0;$i<count($tr);$i++)
  37.     {
  38.         if(array_key_exists('args', $tr[$i])) $tr[$i]['args'] = array_map('gettype', $tr[$i]['args']);
  39.         echo '#'.$i.' ';
  40.         //var_dump($tr[$i]);die();
  41.         $str=$tr[$i]['file'].':'.$tr[$i]['line'].' -> '.$tr[$i]['function'];
  42.         if(array_key_exists('args', $tr[$i])) $str.='('.implode($tr[$i]['args']).')';
  43.         echo $str."<br/>\r\n";
  44.     }
  45.     var_dump('test');//*/
  46.     return false;
  47.     //return true;
  48. }
  49. set_error_handler('error_handler', E_ALL);
  50. set_exception_handler('exception_handler');
  51. try
  52. {
  53. //trigger_error("Cannot divide by zero", E_USER_ERROR);
  54. }
  55. catch(Throwable $e){}
  56. try
  57. {
  58. throw new Exception('my Uncaught Exception');
  59. }
  60. catch(Throwable $e){}
  61. ?>
Add Comment
Please, Sign In to add comment