"Php Error",
2 => "Php Warning",
4 => "Parsing Error",
8 => "Php Notice",
16 => "Core Error",
32 => "Core Warning",
64 => "Compile Error",
128 => "Compile Warning",
256 => "Php User Error",
512 => "Php User Warning",
1024 => "Php User Notice"
);
/**
* @param int $errNo
* @param string $errMsg
* @param string $file
* @param int $line
* @return void
* @access public
*/
public static function raiseError($errNo, $errMsg, $file, $line)
{
global $me;
//if we ignore errors.. bounce
if (!($errNo & error_reporting()))
return;
//clear our buggers
while (ob_get_level())
ob_end_clean();
//its its a user error... unserialize it.
$info = array();
if (($errNo & E_USER_ERROR) && is_array($arr = @unserialize($errMsg)))
foreach ($arr as $k => $v)
$info[$k] = $v;
else
$info = $errMsg . " on line $line";
//can we get a backtrace?
$trace = array();
if (function_exists('debug_backtrace'))
{
$trace = debug_backtrace();
array_shift($trace);
}
//what shoudl we do?
if ($me instanceOf User && $me->isAdmin())
echo self::getBacktrace($info, $trace, $errNo);
else
echo self::getReportErrorForm($info, $trace, $errNo);
exit;
}
public static function handleException($e)
{
global $me;
//get our information
$info = $e->getMessage();
$trace = $e->getTrace();
$errNo = $e->getCode();
//what shoudl we do?
if (($me instanceOf User && $me->isAdmin()) || !($me instanceOf User))
{
echo "
Uncaught Exception: " . get_class($e) . "
\n\n";
echo self::getBacktrace($info, $trace, $errNo);
}
else
echo self::getReportErrorForm($info, $trace, $errNo);
exit;
}
public static function getBacktrace($info, $trace, $errNo = null)
{
//init our string.
$s = '';
if ($errNo)
$s .= "Error type: " . self::$errType[$errNo] . "
\n";
$c['default'] = '#000000';
$c['keyword'] = '#0000A0';
$c['number'] = '#800080';
$c['string'] = '#404040';
$c['comment'] = '#808080';
if (is_array($info) && count($info))
foreach ($info as $k => $v)
$s .= "$k: $v
\n";
else if ($info)
$s .= "Message: $info
\n";
//did we get a trace?
if (count($trace))
{
$s .= "Trace:\n";
$s .= "\n";
$currentParam = -1;
//show all our trace.
foreach ($trace as $k => $v)
{
$currentParam++;
$s .= "\t- ";
//was there a class?
if (isset($v['class']))
{
$s .= $v['class'];
$s .= ".";
}
//show the function.
$s .= $v['function'];
$s .= " (";
//and its args...
$sep = '';
$v['args'] = (array) @$v['args'];
foreach ($v['args'] as $arg)
{
$currentParam++;
$s .= $sep;
$sep = ', ';
$color = '#404040';
switch (true)
{
case is_bool($arg):
$type = 'bool';
if ($arg)
$param = 'true';
else
$param = 'false';
break;
case is_int($arg):
case is_float($arg):
$type = 'number';
$param = $arg;
break;
case is_null($arg):
$param = 'null';
$type = $param;
break;
case is_string($arg):
$type = 'string[' . strlen($arg) . ']';
$param = $arg;
break;
case is_array($arg):
$type = 'array[' . count($arg) . ']';
ob_start();
print_r($arg);
$param = ob_get_contents();
ob_end_clean();
break;
case is_object($arg):
$type = 'object';
$param = get_class($arg);
break;
case is_resource($arg):
$type = 'resource';
$param = get_resource_type($arg);
break;
default:
$param = 'unknown';
$type = $param;
break;
}
$s .= "";
$s .= $type . ": " . $param;
$s .= '';
}
$s .= ")";
$s .= "
\n";
//now show the file.
if (!isset($v['file']))
$v['file'] = 'unknown';
if (!isset($v['line']))
$v['line'] = 'unknown';
//where?
$v['line'] = @$v['line'];
$s .= "\tLocation: $v[file] (Line: $v[line])";
$s .= " \n";
}
$s .= "
\n";
}
else
$s .= "Could not get backtrace!\n";
return $s;
}
public static function getReportErrorForm($info, $trace, $errNo = null)
{
//do we have a main class?
if (class_exists('Main'))
{
//draw our form!
$main = new Main();
$backtrace = base64_encode(self::getBacktrace($info, $trace, $errNo));
$form = $main->createErrorForm($backtrace);
$form->drawAll();
}
//nope, draw our error text.
else
echo "There was an error. Please contact " .
Linkify::email(SITE_ADMIN) . " and let them know you have a
problem. Please include information like what you were doing, what
page you were on, etc.";
}
}
//create our error handler and make it the object..
$__ErrorHandler = new ErrorHandler;
set_error_handler(array(&$__ErrorHandler, 'raiseError'));
?>