public function ErrorHandler::handleError in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/debug/ErrorHandler.php \Symfony\Component\Debug\ErrorHandler::handleError()
Handles errors by filtering then logging them according to the configured bit fields.
@internal
Parameters
int $type One of the E_* constants:
string $file:
int $line:
array $context:
Return value
bool Returns false when no handling happens so that the PHP engine can handle the error itself.
Throws
\ErrorException When $this->thrownErrors requests so
1 call to ErrorHandler::handleError()
- ErrorHandler::handle in vendor/
symfony/ debug/ ErrorHandler.php
File
- vendor/
symfony/ debug/ ErrorHandler.php, line 353
Class
- ErrorHandler
- A generic ErrorHandler for the PHP engine.
Namespace
Symfony\Component\DebugCode
public function handleError($type, $message, $file, $line, array $context, array $backtrace = null) {
$level = error_reporting() | E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
$log = $this->loggedErrors & $type;
$throw = $this->thrownErrors & $type & $level;
$type &= $level | $this->screamedErrors;
if (!$type || !$log && !$throw) {
return $type && $log;
}
if (PHP_VERSION_ID < 50400 && isset($context['GLOBALS']) && $this->scopedErrors & $type) {
$e = $context;
// Whatever the signature of the method,
unset($e['GLOBALS'], $context);
// $context is always a reference in 5.3
$context = $e;
}
if (null !== $backtrace && $type & E_ERROR) {
// E_ERROR fatal errors are triggered on HHVM when
// hhvm.error_handling.call_user_handler_on_fatals=1
// which is the way to get their backtrace.
$this
->handleFatalError(compact('type', 'message', 'file', 'line', 'backtrace'));
return true;
}
if ($throw) {
if ($this->scopedErrors & $type && class_exists('Symfony\\Component\\Debug\\Exception\\ContextErrorException')) {
// Checking for class existence is a work around for https://bugs.php.net/42098
$throw = new ContextErrorException($this->levels[$type] . ': ' . $message, 0, $type, $file, $line, $context);
}
else {
$throw = new \ErrorException($this->levels[$type] . ': ' . $message, 0, $type, $file, $line);
}
if (PHP_VERSION_ID <= 50407 && (PHP_VERSION_ID >= 50400 || PHP_VERSION_ID <= 50317)) {
// Exceptions thrown from error handlers are sometimes not caught by the exception
// handler and shutdown handlers are bypassed before 5.4.8/5.3.18.
// We temporarily re-enable display_errors to prevent any blank page related to this bug.
$throw->errorHandlerCanary = new ErrorHandlerCanary();
}
throw $throw;
}
// For duplicated errors, log the trace only once
$e = md5("{$type}/{$line}/{$file}\0{$message}", true);
$trace = true;
if (!($this->tracedErrors & $type) || isset($this->loggedTraces[$e])) {
$trace = false;
}
else {
$this->loggedTraces[$e] = 1;
}
$e = compact('type', 'file', 'line', 'level');
if ($type & $level) {
if ($this->scopedErrors & $type) {
$e['scope_vars'] = $context;
if ($trace) {
$e['stack'] = $backtrace ?: debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
}
}
elseif ($trace) {
if (null === $backtrace) {
$e['stack'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
else {
foreach ($backtrace as &$frame) {
unset($frame['args'], $frame);
}
$e['stack'] = $backtrace;
}
}
}
if ($this->isRecursive) {
$log = 0;
}
elseif (self::$stackedErrorLevels) {
self::$stackedErrors[] = array(
$this->loggers[$type][0],
$type & $level ? $this->loggers[$type][1] : LogLevel::DEBUG,
$message,
$e,
);
}
else {
try {
$this->isRecursive = true;
$this->loggers[$type][0]
->log($type & $level ? $this->loggers[$type][1] : LogLevel::DEBUG, $message, $e);
$this->isRecursive = false;
} catch (\Exception $e) {
$this->isRecursive = false;
throw $e;
}
}
return $type && $log;
}