FatalErrorException.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /**
  12. * Fatal Error Exception.
  13. *
  14. * @author Konstanton Myakshin <koc-dp@yandex.ru>
  15. */
  16. class FatalErrorException extends \ErrorException
  17. {
  18. public function __construct(string $message, int $code, int $severity, string $filename, int $lineno, int $traceOffset = null, bool $traceArgs = true, array $trace = null)
  19. {
  20. parent::__construct($message, $code, $severity, $filename, $lineno);
  21. if (null !== $trace) {
  22. if (!$traceArgs) {
  23. foreach ($trace as &$frame) {
  24. unset($frame['args'], $frame['this'], $frame);
  25. }
  26. }
  27. $this->setTrace($trace);
  28. } elseif (null !== $traceOffset) {
  29. if (function_exists('xdebug_get_function_stack')) {
  30. $trace = xdebug_get_function_stack();
  31. if (0 < $traceOffset) {
  32. array_splice($trace, -$traceOffset);
  33. }
  34. foreach ($trace as &$frame) {
  35. if (!isset($frame['type'])) {
  36. // XDebug pre 2.1.1 doesn't currently set the call type key http://bugs.xdebug.org/view.php?id=695
  37. if (isset($frame['class'])) {
  38. $frame['type'] = '::';
  39. }
  40. } elseif ('dynamic' === $frame['type']) {
  41. $frame['type'] = '->';
  42. } elseif ('static' === $frame['type']) {
  43. $frame['type'] = '::';
  44. }
  45. // XDebug also has a different name for the parameters array
  46. if (!$traceArgs) {
  47. unset($frame['params'], $frame['args']);
  48. } elseif (isset($frame['params']) && !isset($frame['args'])) {
  49. $frame['args'] = $frame['params'];
  50. unset($frame['params']);
  51. }
  52. }
  53. unset($frame);
  54. $trace = array_reverse($trace);
  55. } else {
  56. $trace = array();
  57. }
  58. $this->setTrace($trace);
  59. }
  60. }
  61. protected function setTrace($trace)
  62. {
  63. $traceReflector = new \ReflectionProperty('Exception', 'trace');
  64. $traceReflector->setAccessible(true);
  65. $traceReflector->setValue($this, $trace);
  66. }
  67. }