FatalErrorException.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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($message, $code, $severity, $filename, $lineno, $traceOffset = null, $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. } elseif (function_exists('symfony_debug_backtrace')) {
  56. $trace = symfony_debug_backtrace();
  57. if (0 < $traceOffset) {
  58. array_splice($trace, 0, $traceOffset);
  59. }
  60. } else {
  61. $trace = array();
  62. }
  63. $this->setTrace($trace);
  64. }
  65. }
  66. protected function setTrace($trace)
  67. {
  68. $traceReflector = new \ReflectionProperty('Exception', 'trace');
  69. $traceReflector->setAccessible(true);
  70. $traceReflector->setValue($this, $trace);
  71. }
  72. }