FatalErrorException.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Debug\Exception;
  11. @trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalErrorException::class, \Symfony\Component\ErrorHandler\Error\FatalError::class), \E_USER_DEPRECATED);
  12. /**
  13. * Fatal Error Exception.
  14. *
  15. * @author Konstanton Myakshin <koc-dp@yandex.ru>
  16. *
  17. * @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\FatalError instead.
  18. */
  19. class FatalErrorException extends \ErrorException
  20. {
  21. public function __construct(string $message, int $code, int $severity, string $filename, int $lineno, int $traceOffset = null, bool $traceArgs = true, array $trace = null, \Throwable $previous = null)
  22. {
  23. parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
  24. if (null !== $trace) {
  25. if (!$traceArgs) {
  26. foreach ($trace as &$frame) {
  27. unset($frame['args'], $frame['this'], $frame);
  28. }
  29. }
  30. $this->setTrace($trace);
  31. } elseif (null !== $traceOffset) {
  32. if (\function_exists('xdebug_get_function_stack')) {
  33. $trace = xdebug_get_function_stack();
  34. if (0 < $traceOffset) {
  35. array_splice($trace, -$traceOffset);
  36. }
  37. foreach ($trace as &$frame) {
  38. if (!isset($frame['type'])) {
  39. // XDebug pre 2.1.1 doesn't currently set the call type key http://bugs.xdebug.org/view.php?id=695
  40. if (isset($frame['class'])) {
  41. $frame['type'] = '::';
  42. }
  43. } elseif ('dynamic' === $frame['type']) {
  44. $frame['type'] = '->';
  45. } elseif ('static' === $frame['type']) {
  46. $frame['type'] = '::';
  47. }
  48. // XDebug also has a different name for the parameters array
  49. if (!$traceArgs) {
  50. unset($frame['params'], $frame['args']);
  51. } elseif (isset($frame['params']) && !isset($frame['args'])) {
  52. $frame['args'] = $frame['params'];
  53. unset($frame['params']);
  54. }
  55. }
  56. unset($frame);
  57. $trace = array_reverse($trace);
  58. } else {
  59. $trace = [];
  60. }
  61. $this->setTrace($trace);
  62. }
  63. }
  64. protected function setTrace($trace)
  65. {
  66. $traceReflector = new \ReflectionProperty(\Exception::class, 'trace');
  67. $traceReflector->setAccessible(true);
  68. $traceReflector->setValue($this, $trace);
  69. }
  70. }