6 function ErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
9 $error_msg = " $errstr occured in $errfile on $errline at ".date("D M j G:i:s T Y");
10 $email_to = 'sql@mit.edu';
11 $email_from = 'sql@sql.mit.edu';
19 case E_COMPILE_WARNING:
29 $type = 'Fatal Error';
32 $type = 'Parse Error';
35 $type = 'Unknown Error';
38 $error_bt = ErrorBacktrace(debug_backtrace());
39 $error_msg = $type . ':' . $error_msg . "\n" . $error_bt . "\n\n";
41 echo '<table width="100%" bgcolor="white"><tr><td><pre>'.$error_msg.'</pre></td></tr></table>';
43 $error_msg .= print_r(get_included_files(),1)."\n";
44 $error_msg .= print_r($errcontext,1);
45 error_log($error_msg, 1, $email_to);
47 while(ob_get_level()) { ob_end_clean(); }
48 require_once('security.lib.php');
55 function ErrorBacktrace($debug_backtrace) {
56 array_shift($debug_backtrace);
58 foreach ($debug_backtrace as $bt) {
60 foreach ($bt['args'] as $a) {
64 switch (gettype($a)) {
70 $a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : '');
74 //$args .= 'Array('.count($a).')';
75 $args .= print_r($a,1);
78 $args .= 'Object('.get_class($a).')';
81 $args .= 'Resource('.strstr($a, '#').')';
84 $args .= $a ? 'True' : 'False';
93 empty($bt['class']) && $bt['class'] = '';
94 empty($bt['type']) && $bt['type'] = '';
95 empty($bt['function']) && $bt['function'] = '';
97 $output .= "file: {$bt['line']} - {$bt['file']}\n";
98 $output .= "call: {$bt['class']}{$bt['type']}{$bt['function']}($args)\n";
103 set_error_handler('ErrorHandler');