composer package updates
[openemr.git] / vendor / symfony / debug / ErrorHandler.php
blobbed0e04a476df4e8a17c2e156583ee4f09ea2d39
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Debug;
14 use Psr\Log\LogLevel;
15 use Psr\Log\LoggerInterface;
16 use Symfony\Component\Debug\Exception\ContextErrorException;
17 use Symfony\Component\Debug\Exception\FatalErrorException;
18 use Symfony\Component\Debug\Exception\FatalThrowableError;
19 use Symfony\Component\Debug\Exception\OutOfMemoryException;
20 use Symfony\Component\Debug\Exception\SilencedErrorContext;
21 use Symfony\Component\Debug\FatalErrorHandler\UndefinedFunctionFatalErrorHandler;
22 use Symfony\Component\Debug\FatalErrorHandler\UndefinedMethodFatalErrorHandler;
23 use Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler;
24 use Symfony\Component\Debug\FatalErrorHandler\FatalErrorHandlerInterface;
26 /**
27 * A generic ErrorHandler for the PHP engine.
29 * Provides five bit fields that control how errors are handled:
30 * - thrownErrors: errors thrown as \ErrorException
31 * - loggedErrors: logged errors, when not @-silenced
32 * - scopedErrors: errors thrown or logged with their local context
33 * - tracedErrors: errors logged with their stack trace
34 * - screamedErrors: never @-silenced errors
36 * Each error level can be logged by a dedicated PSR-3 logger object.
37 * Screaming only applies to logging.
38 * Throwing takes precedence over logging.
39 * Uncaught exceptions are logged as E_ERROR.
40 * E_DEPRECATED and E_USER_DEPRECATED levels never throw.
41 * E_RECOVERABLE_ERROR and E_USER_ERROR levels always throw.
42 * Non catchable errors that can be detected at shutdown time are logged when the scream bit field allows so.
43 * As errors have a performance cost, repeated errors are all logged, so that the developer
44 * can see them and weight them as more important to fix than others of the same level.
46 * @author Nicolas Grekas <p@tchwork.com>
47 * @author Grégoire Pineau <lyrixx@lyrixx.info>
49 class ErrorHandler
51 private $levels = array(
52 E_DEPRECATED => 'Deprecated',
53 E_USER_DEPRECATED => 'User Deprecated',
54 E_NOTICE => 'Notice',
55 E_USER_NOTICE => 'User Notice',
56 E_STRICT => 'Runtime Notice',
57 E_WARNING => 'Warning',
58 E_USER_WARNING => 'User Warning',
59 E_COMPILE_WARNING => 'Compile Warning',
60 E_CORE_WARNING => 'Core Warning',
61 E_USER_ERROR => 'User Error',
62 E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
63 E_COMPILE_ERROR => 'Compile Error',
64 E_PARSE => 'Parse Error',
65 E_ERROR => 'Error',
66 E_CORE_ERROR => 'Core Error',
69 private $loggers = array(
70 E_DEPRECATED => array(null, LogLevel::INFO),
71 E_USER_DEPRECATED => array(null, LogLevel::INFO),
72 E_NOTICE => array(null, LogLevel::WARNING),
73 E_USER_NOTICE => array(null, LogLevel::WARNING),
74 E_STRICT => array(null, LogLevel::WARNING),
75 E_WARNING => array(null, LogLevel::WARNING),
76 E_USER_WARNING => array(null, LogLevel::WARNING),
77 E_COMPILE_WARNING => array(null, LogLevel::WARNING),
78 E_CORE_WARNING => array(null, LogLevel::WARNING),
79 E_USER_ERROR => array(null, LogLevel::CRITICAL),
80 E_RECOVERABLE_ERROR => array(null, LogLevel::CRITICAL),
81 E_COMPILE_ERROR => array(null, LogLevel::CRITICAL),
82 E_PARSE => array(null, LogLevel::CRITICAL),
83 E_ERROR => array(null, LogLevel::CRITICAL),
84 E_CORE_ERROR => array(null, LogLevel::CRITICAL),
87 private $thrownErrors = 0x1FFF; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED
88 private $scopedErrors = 0x1FFF; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED
89 private $tracedErrors = 0x77FB; // E_ALL - E_STRICT - E_PARSE
90 private $screamedErrors = 0x55; // E_ERROR + E_CORE_ERROR + E_COMPILE_ERROR + E_PARSE
91 private $loggedErrors = 0;
92 private $traceReflector;
94 private $isRecursive = 0;
95 private $isRoot = false;
96 private $exceptionHandler;
97 private $bootstrappingLogger;
99 private static $reservedMemory;
100 private static $stackedErrors = array();
101 private static $stackedErrorLevels = array();
102 private static $toStringException = null;
103 private static $silencedErrorCache = array();
104 private static $silencedErrorCount = 0;
105 private static $exitCode = 0;
108 * Registers the error handler.
110 * @param self|null $handler The handler to register
111 * @param bool $replace Whether to replace or not any existing handler
113 * @return self The registered error handler
115 public static function register(self $handler = null, $replace = true)
117 if (null === self::$reservedMemory) {
118 self::$reservedMemory = str_repeat('x', 10240);
119 register_shutdown_function(__CLASS__.'::handleFatalError');
122 if ($handlerIsNew = null === $handler) {
123 $handler = new static();
126 if (null === $prev = set_error_handler(array($handler, 'handleError'))) {
127 restore_error_handler();
128 // Specifying the error types earlier would expose us to https://bugs.php.net/63206
129 set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
130 $handler->isRoot = true;
133 if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) {
134 $handler = $prev[0];
135 $replace = false;
137 if (!$replace && $prev) {
138 restore_error_handler();
139 $handlerIsRegistered = is_array($prev) && $handler === $prev[0];
140 } else {
141 $handlerIsRegistered = true;
143 if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] instanceof self) {
144 restore_exception_handler();
145 if (!$handlerIsRegistered) {
146 $handler = $prev[0];
147 } elseif ($handler !== $prev[0] && $replace) {
148 set_exception_handler(array($handler, 'handleException'));
149 $p = $prev[0]->setExceptionHandler(null);
150 $handler->setExceptionHandler($p);
151 $prev[0]->setExceptionHandler($p);
153 } else {
154 $handler->setExceptionHandler($prev);
157 $handler->throwAt(E_ALL & $handler->thrownErrors, true);
159 return $handler;
162 public function __construct(BufferingLogger $bootstrappingLogger = null)
164 if ($bootstrappingLogger) {
165 $this->bootstrappingLogger = $bootstrappingLogger;
166 $this->setDefaultLogger($bootstrappingLogger);
168 $this->traceReflector = new \ReflectionProperty('Exception', 'trace');
169 $this->traceReflector->setAccessible(true);
173 * Sets a logger to non assigned errors levels.
175 * @param LoggerInterface $logger A PSR-3 logger to put as default for the given levels
176 * @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
177 * @param bool $replace Whether to replace or not any existing logger
179 public function setDefaultLogger(LoggerInterface $logger, $levels = E_ALL, $replace = false)
181 $loggers = array();
183 if (is_array($levels)) {
184 foreach ($levels as $type => $logLevel) {
185 if (empty($this->loggers[$type][0]) || $replace || $this->loggers[$type][0] === $this->bootstrappingLogger) {
186 $loggers[$type] = array($logger, $logLevel);
189 } else {
190 if (null === $levels) {
191 $levels = E_ALL;
193 foreach ($this->loggers as $type => $log) {
194 if (($type & $levels) && (empty($log[0]) || $replace || $log[0] === $this->bootstrappingLogger)) {
195 $log[0] = $logger;
196 $loggers[$type] = $log;
201 $this->setLoggers($loggers);
205 * Sets a logger for each error level.
207 * @param array $loggers Error levels to [LoggerInterface|null, LogLevel::*] map
209 * @return array The previous map
211 * @throws \InvalidArgumentException
213 public function setLoggers(array $loggers)
215 $prevLogged = $this->loggedErrors;
216 $prev = $this->loggers;
217 $flush = array();
219 foreach ($loggers as $type => $log) {
220 if (!isset($prev[$type])) {
221 throw new \InvalidArgumentException('Unknown error type: '.$type);
223 if (!is_array($log)) {
224 $log = array($log);
225 } elseif (!array_key_exists(0, $log)) {
226 throw new \InvalidArgumentException('No logger provided');
228 if (null === $log[0]) {
229 $this->loggedErrors &= ~$type;
230 } elseif ($log[0] instanceof LoggerInterface) {
231 $this->loggedErrors |= $type;
232 } else {
233 throw new \InvalidArgumentException('Invalid logger provided');
235 $this->loggers[$type] = $log + $prev[$type];
237 if ($this->bootstrappingLogger && $prev[$type][0] === $this->bootstrappingLogger) {
238 $flush[$type] = $type;
241 $this->reRegister($prevLogged | $this->thrownErrors);
243 if ($flush) {
244 foreach ($this->bootstrappingLogger->cleanLogs() as $log) {
245 $type = $log[2]['exception'] instanceof \ErrorException ? $log[2]['exception']->getSeverity() : E_ERROR;
246 if (!isset($flush[$type])) {
247 $this->bootstrappingLogger->log($log[0], $log[1], $log[2]);
248 } elseif ($this->loggers[$type][0]) {
249 $this->loggers[$type][0]->log($this->loggers[$type][1], $log[1], $log[2]);
254 return $prev;
258 * Sets a user exception handler.
260 * @param callable $handler A handler that will be called on Exception
262 * @return callable|null The previous exception handler
264 public function setExceptionHandler(callable $handler = null)
266 $prev = $this->exceptionHandler;
267 $this->exceptionHandler = $handler;
269 return $prev;
273 * Sets the PHP error levels that throw an exception when a PHP error occurs.
275 * @param int $levels A bit field of E_* constants for thrown errors
276 * @param bool $replace Replace or amend the previous value
278 * @return int The previous value
280 public function throwAt($levels, $replace = false)
282 $prev = $this->thrownErrors;
283 $this->thrownErrors = ($levels | E_RECOVERABLE_ERROR | E_USER_ERROR) & ~E_USER_DEPRECATED & ~E_DEPRECATED;
284 if (!$replace) {
285 $this->thrownErrors |= $prev;
287 $this->reRegister($prev | $this->loggedErrors);
289 return $prev;
293 * Sets the PHP error levels for which local variables are preserved.
295 * @param int $levels A bit field of E_* constants for scoped errors
296 * @param bool $replace Replace or amend the previous value
298 * @return int The previous value
300 public function scopeAt($levels, $replace = false)
302 $prev = $this->scopedErrors;
303 $this->scopedErrors = (int) $levels;
304 if (!$replace) {
305 $this->scopedErrors |= $prev;
308 return $prev;
312 * Sets the PHP error levels for which the stack trace is preserved.
314 * @param int $levels A bit field of E_* constants for traced errors
315 * @param bool $replace Replace or amend the previous value
317 * @return int The previous value
319 public function traceAt($levels, $replace = false)
321 $prev = $this->tracedErrors;
322 $this->tracedErrors = (int) $levels;
323 if (!$replace) {
324 $this->tracedErrors |= $prev;
327 return $prev;
331 * Sets the error levels where the @-operator is ignored.
333 * @param int $levels A bit field of E_* constants for screamed errors
334 * @param bool $replace Replace or amend the previous value
336 * @return int The previous value
338 public function screamAt($levels, $replace = false)
340 $prev = $this->screamedErrors;
341 $this->screamedErrors = (int) $levels;
342 if (!$replace) {
343 $this->screamedErrors |= $prev;
346 return $prev;
350 * Re-registers as a PHP error handler if levels changed.
352 private function reRegister($prev)
354 if ($prev !== $this->thrownErrors | $this->loggedErrors) {
355 $handler = set_error_handler('var_dump');
356 $handler = is_array($handler) ? $handler[0] : null;
357 restore_error_handler();
358 if ($handler === $this) {
359 restore_error_handler();
360 if ($this->isRoot) {
361 set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
362 } else {
363 set_error_handler(array($this, 'handleError'));
370 * Handles errors by filtering then logging them according to the configured bit fields.
372 * @param int $type One of the E_* constants
373 * @param string $message
374 * @param string $file
375 * @param int $line
377 * @return bool Returns false when no handling happens so that the PHP engine can handle the error itself
379 * @throws \ErrorException When $this->thrownErrors requests so
381 * @internal
383 public function handleError($type, $message, $file, $line)
385 // Level is the current error reporting level to manage silent error.
386 $level = error_reporting();
387 $silenced = 0 === ($level & $type);
388 // Strong errors are not authorized to be silenced.
389 $level |= E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
390 $log = $this->loggedErrors & $type;
391 $throw = $this->thrownErrors & $type & $level;
392 $type &= $level | $this->screamedErrors;
394 if (!$type || (!$log && !$throw)) {
395 return !$silenced && $type && $log;
397 $scope = $this->scopedErrors & $type;
399 if (4 < $numArgs = func_num_args()) {
400 $context = $scope ? (func_get_arg(4) ?: array()) : array();
401 $backtrace = 5 < $numArgs ? func_get_arg(5) : null; // defined on HHVM
402 } else {
403 $context = array();
404 $backtrace = null;
407 if (isset($context['GLOBALS']) && $scope) {
408 $e = $context; // Whatever the signature of the method,
409 unset($e['GLOBALS'], $context); // $context is always a reference in 5.3
410 $context = $e;
413 if (null !== $backtrace && $type & E_ERROR) {
414 // E_ERROR fatal errors are triggered on HHVM when
415 // hhvm.error_handling.call_user_handler_on_fatals=1
416 // which is the way to get their backtrace.
417 $this->handleFatalError(compact('type', 'message', 'file', 'line', 'backtrace'));
419 return true;
422 $logMessage = $this->levels[$type].': '.$message;
424 if (null !== self::$toStringException) {
425 $errorAsException = self::$toStringException;
426 self::$toStringException = null;
427 } elseif (!$throw && !($type & $level)) {
428 if (!isset(self::$silencedErrorCache[$id = $file.':'.$line])) {
429 $lightTrace = $this->tracedErrors & $type ? $this->cleanTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3), $type, $file, $line, false) : array();
430 $errorAsException = new SilencedErrorContext($type, $file, $line, $lightTrace);
431 } elseif (isset(self::$silencedErrorCache[$id][$message])) {
432 $lightTrace = null;
433 $errorAsException = self::$silencedErrorCache[$id][$message];
434 ++$errorAsException->count;
435 } else {
436 $lightTrace = array();
437 $errorAsException = null;
440 if (100 < ++self::$silencedErrorCount) {
441 self::$silencedErrorCache = $lightTrace = array();
442 self::$silencedErrorCount = 1;
444 if ($errorAsException) {
445 self::$silencedErrorCache[$id][$message] = $errorAsException;
447 if (null === $lightTrace) {
448 return;
450 } else {
451 if ($scope) {
452 $errorAsException = new ContextErrorException($logMessage, 0, $type, $file, $line, $context);
453 } else {
454 $errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line);
457 // Clean the trace by removing function arguments and the first frames added by the error handler itself.
458 if ($throw || $this->tracedErrors & $type) {
459 $backtrace = $backtrace ?: $errorAsException->getTrace();
460 $lightTrace = $this->cleanTrace($backtrace, $type, $file, $line, $throw);
461 $this->traceReflector->setValue($errorAsException, $lightTrace);
462 } else {
463 $this->traceReflector->setValue($errorAsException, array());
467 if ($throw) {
468 if (E_USER_ERROR & $type) {
469 for ($i = 1; isset($backtrace[$i]); ++$i) {
470 if (isset($backtrace[$i]['function'], $backtrace[$i]['type'], $backtrace[$i - 1]['function'])
471 && '__toString' === $backtrace[$i]['function']
472 && '->' === $backtrace[$i]['type']
473 && !isset($backtrace[$i - 1]['class'])
474 && ('trigger_error' === $backtrace[$i - 1]['function'] || 'user_error' === $backtrace[$i - 1]['function'])
476 // Here, we know trigger_error() has been called from __toString().
477 // HHVM is fine with throwing from __toString() but PHP triggers a fatal error instead.
478 // A small convention allows working around the limitation:
479 // given a caught $e exception in __toString(), quitting the method with
480 // `return trigger_error($e, E_USER_ERROR);` allows this error handler
481 // to make $e get through the __toString() barrier.
483 foreach ($context as $e) {
484 if (($e instanceof \Exception || $e instanceof \Throwable) && $e->__toString() === $message) {
485 if (1 === $i) {
486 // On HHVM
487 $errorAsException = $e;
488 break;
490 self::$toStringException = $e;
492 return true;
496 if (1 < $i) {
497 // On PHP (not on HHVM), display the original error message instead of the default one.
498 $this->handleException($errorAsException);
500 // Stop the process by giving back the error to the native handler.
501 return false;
507 throw $errorAsException;
510 if ($this->isRecursive) {
511 $log = 0;
512 } elseif (self::$stackedErrorLevels) {
513 self::$stackedErrors[] = array(
514 $this->loggers[$type][0],
515 ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG,
516 $logMessage,
517 $errorAsException ? array('exception' => $errorAsException) : array(),
519 } else {
520 try {
521 $this->isRecursive = true;
522 $level = ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG;
523 $this->loggers[$type][0]->log($level, $logMessage, $errorAsException ? array('exception' => $errorAsException) : array());
524 } finally {
525 $this->isRecursive = false;
529 return !$silenced && $type && $log;
533 * Handles an exception by logging then forwarding it to another handler.
535 * @param \Exception|\Throwable $exception An exception to handle
536 * @param array $error An array as returned by error_get_last()
538 * @internal
540 public function handleException($exception, array $error = null)
542 if (null === $error) {
543 self::$exitCode = 255;
545 if (!$exception instanceof \Exception) {
546 $exception = new FatalThrowableError($exception);
548 $type = $exception instanceof FatalErrorException ? $exception->getSeverity() : E_ERROR;
549 $handlerException = null;
551 if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
552 if ($exception instanceof FatalErrorException) {
553 if ($exception instanceof FatalThrowableError) {
554 $error = array(
555 'type' => $type,
556 'message' => $message = $exception->getMessage(),
557 'file' => $exception->getFile(),
558 'line' => $exception->getLine(),
560 } else {
561 $message = 'Fatal '.$exception->getMessage();
563 } elseif ($exception instanceof \ErrorException) {
564 $message = 'Uncaught '.$exception->getMessage();
565 } else {
566 $message = 'Uncaught Exception: '.$exception->getMessage();
569 if ($this->loggedErrors & $type) {
570 try {
571 $this->loggers[$type][0]->log($this->loggers[$type][1], $message, array('exception' => $exception));
572 } catch (\Exception $handlerException) {
573 } catch (\Throwable $handlerException) {
576 if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) {
577 foreach ($this->getFatalErrorHandlers() as $handler) {
578 if ($e = $handler->handleError($error, $exception)) {
579 $exception = $e;
580 break;
584 $exceptionHandler = $this->exceptionHandler;
585 $this->exceptionHandler = null;
586 try {
587 if (null !== $exceptionHandler) {
588 return \call_user_func($exceptionHandler, $exception);
590 $handlerException = $handlerException ?: $exception;
591 } catch (\Exception $handlerException) {
592 } catch (\Throwable $handlerException) {
594 if ($exception === $handlerException) {
595 self::$reservedMemory = null; // Disable the fatal error handler
596 throw $exception; // Give back $exception to the native handler
598 $this->handleException($handlerException);
602 * Shutdown registered function for handling PHP fatal errors.
604 * @param array $error An array as returned by error_get_last()
606 * @internal
608 public static function handleFatalError(array $error = null)
610 if (null === self::$reservedMemory) {
611 return;
614 $handler = self::$reservedMemory = null;
615 $handlers = array();
616 $previousHandler = null;
617 $sameHandlerLimit = 10;
619 while (!is_array($handler) || !$handler[0] instanceof self) {
620 $handler = set_exception_handler('var_dump');
621 restore_exception_handler();
623 if (!$handler) {
624 break;
626 restore_exception_handler();
628 if ($handler !== $previousHandler) {
629 array_unshift($handlers, $handler);
630 $previousHandler = $handler;
631 } elseif (0 === --$sameHandlerLimit) {
632 $handler = null;
633 break;
636 foreach ($handlers as $h) {
637 set_exception_handler($h);
639 if (!$handler) {
640 return;
642 if ($handler !== $h) {
643 $handler[0]->setExceptionHandler($h);
645 $handler = $handler[0];
646 $handlers = array();
648 if ($exit = null === $error) {
649 $error = error_get_last();
652 try {
653 while (self::$stackedErrorLevels) {
654 static::unstackErrors();
656 } catch (\Exception $exception) {
657 // Handled below
658 } catch (\Throwable $exception) {
659 // Handled below
662 if ($error && $error['type'] &= E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR) {
663 // Let's not throw anymore but keep logging
664 $handler->throwAt(0, true);
665 $trace = isset($error['backtrace']) ? $error['backtrace'] : null;
667 if (0 === strpos($error['message'], 'Allowed memory') || 0 === strpos($error['message'], 'Out of memory')) {
668 $exception = new OutOfMemoryException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, false, $trace);
669 } else {
670 $exception = new FatalErrorException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true, $trace);
674 try {
675 if (isset($exception)) {
676 self::$exitCode = 255;
677 $handler->handleException($exception, $error);
679 } catch (FatalErrorException $e) {
680 // Ignore this re-throw
683 if ($exit && self::$exitCode) {
684 $exitCode = self::$exitCode;
685 register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
690 * Configures the error handler for delayed handling.
691 * Ensures also that non-catchable fatal errors are never silenced.
693 * As shown by http://bugs.php.net/42098 and http://bugs.php.net/60724
694 * PHP has a compile stage where it behaves unusually. To workaround it,
695 * we plug an error handler that only stacks errors for later.
697 * The most important feature of this is to prevent
698 * autoloading until unstackErrors() is called.
700 * @deprecated since version 3.4, to be removed in 4.0.
702 public static function stackErrors()
704 @trigger_error('Support for stacking errors is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
706 self::$stackedErrorLevels[] = error_reporting(error_reporting() | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR);
710 * Unstacks stacked errors and forwards to the logger.
712 * @deprecated since version 3.4, to be removed in 4.0.
714 public static function unstackErrors()
716 @trigger_error('Support for unstacking errors is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
718 $level = array_pop(self::$stackedErrorLevels);
720 if (null !== $level) {
721 $errorReportingLevel = error_reporting($level);
722 if ($errorReportingLevel !== ($level | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR)) {
723 // If the user changed the error level, do not overwrite it
724 error_reporting($errorReportingLevel);
728 if (empty(self::$stackedErrorLevels)) {
729 $errors = self::$stackedErrors;
730 self::$stackedErrors = array();
732 foreach ($errors as $error) {
733 $error[0]->log($error[1], $error[2], $error[3]);
739 * Gets the fatal error handlers.
741 * Override this method if you want to define more fatal error handlers.
743 * @return FatalErrorHandlerInterface[] An array of FatalErrorHandlerInterface
745 protected function getFatalErrorHandlers()
747 return array(
748 new UndefinedFunctionFatalErrorHandler(),
749 new UndefinedMethodFatalErrorHandler(),
750 new ClassNotFoundFatalErrorHandler(),
754 private function cleanTrace($backtrace, $type, $file, $line, $throw)
756 $lightTrace = $backtrace;
758 for ($i = 0; isset($backtrace[$i]); ++$i) {
759 if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) {
760 $lightTrace = array_slice($lightTrace, 1 + $i);
761 break;
764 if (!($throw || $this->scopedErrors & $type)) {
765 for ($i = 0; isset($lightTrace[$i]); ++$i) {
766 unset($lightTrace[$i]['args'], $lightTrace[$i]['object']);
770 return $lightTrace;