3 function ErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
6 $error_msg = " $errstr occured in $errfile on $errline at ".date("D M j G:i:s T Y");
7 $email_to = 'sql@mit.edu';
8 $email_from = 'sql@sql.mit.edu';
16 case E_COMPILE_WARNING:
26 $type = 'Fatal Error';
29 $type = 'Parse Error';
32 $type = 'Unknown Error';
35 $error_bt = ErrorBacktrace(debug_backtrace());
36 $error_msg = $type . ':' . $error_msg . "\n" . $error_bt . "\n\n";
38 echo '<table width="100%" bgcolor="white"><tr><td><pre>'.$error_msg.'</pre></td></tr></table>';
40 $error_msg .= print_r(get_included_files(),1)."\n";
41 $error_msg .= print_r($errcontext,1);
42 error_log($error_msg, 1, $email_to);
44 while(ob_get_level()) { ob_end_clean(); }
45 require_once('security.lib.php');
52 function ErrorBacktrace($debug_backtrace) {
53 array_shift($debug_backtrace);
55 foreach ($debug_backtrace as $bt) {
57 foreach ($bt['args'] as $a) {
61 switch (gettype($a)) {
67 $a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : '');
71 //$args .= 'Array('.count($a).')';
72 $args .= print_r($a,1);
75 $args .= 'Object('.get_class($a).')';
78 $args .= 'Resource('.strstr($a, '#').')';
81 $args .= $a ? 'True' : 'False';
90 empty($bt['class']) && $bt['class'] = '';
91 empty($bt['type']) && $bt['type'] = '';
92 empty($bt['function']) && $bt['function'] = '';
94 $output .= "file: {$bt['line']} - {$bt['file']}\n";
95 $output .= "call: {$bt['class']}{$bt['type']}{$bt['function']}($args)\n";
100 set_error_handler('ErrorHandler');