From beb88f759014e5e44a36c2da3f3157119cf93590 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 1 Apr 2015 11:34:18 +0200 Subject: [PATCH] [Debug] Use symfony_debug_backtrace() in FatalErrorException when available --- .../Debug/Exception/FatalErrorException.php | 5 ++ .../Debug/Resources/ext/tests/003.phpt | 85 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/Symfony/Component/Debug/Resources/ext/tests/003.phpt diff --git a/src/Symfony/Component/Debug/Exception/FatalErrorException.php b/src/Symfony/Component/Debug/Exception/FatalErrorException.php index d142051ba9..41bb97c6a9 100644 --- a/src/Symfony/Component/Debug/Exception/FatalErrorException.php +++ b/src/Symfony/Component/Debug/Exception/FatalErrorException.php @@ -69,6 +69,11 @@ class FatalErrorException extends LegacyFatalErrorException unset($frame); $trace = array_reverse($trace); + } elseif (function_exists('symfony_debug_backtrace')) { + $trace = symfony_debug_backtrace(); + if (0 < $traceOffset) { + array_splice($trace, 0, $traceOffset); + } } else { $trace = array(); } diff --git a/src/Symfony/Component/Debug/Resources/ext/tests/003.phpt b/src/Symfony/Component/Debug/Resources/ext/tests/003.phpt new file mode 100644 index 0000000000..1d464720b7 --- /dev/null +++ b/src/Symfony/Component/Debug/Resources/ext/tests/003.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test ErrorHandler in case of fatal error +--SKIPIF-- + +--FILE-- +setExceptionHandler('print_r'); + +if (function_exists('xdebug_disable')) { + xdebug_disable(); +} + +bar(); +?> +--EXPECTF-- +Fatal error: Call to undefined function Symfony\Component\Debug\notexist() in %s on line %d +Symfony\Component\Debug\Exception\UndefinedFunctionException Object +( + [message:protected] => Attempted to call function "notexist" from namespace "Symfony\Component\Debug". + [string:Exception:private] => + [code:protected] => 0 + [file:protected] => - + [line:protected] => %d + [trace:Exception:private] => Array + ( + [0] => Array + ( +%A [function] => Symfony\Component\Debug\foo +%A [args] => Array + ( + ) + + ) + + [1] => Array + ( +%A [function] => Symfony\Component\Debug\bar +%A [args] => Array + ( + ) + + ) +%A + ) + + [previous:Exception:private] => + [severity:protected] => 1 +)