I'm consistently getting an additional stack frame when I look at an exception's trace with the getTraceAsString()
method. It's neither visible in getTrace()
nor in debug_backtrace()
. Where does it come from and what does it mean?
For example, this script:
function foo () {
echo "== debug_backtrace() ==
";
foreach (debug_backtrace() as $i => $frame) {
echo "#$i $frame[file]($frame[line]): $frame[function]()
";
}
throw new Exception();
}
function bar () {
foo();
}
try {
bar();
} catch (Exception $e) {
echo "
== getTrace() ==
";
foreach ($e->getTrace() as $i => $frame) {
echo "#$i $frame[file]($frame[line]): $frame[function]()
";
}
echo "
== getTraceAsString() ==
";
echo $e->getTraceAsString(), "
";
}
produces the following output:
== debug_backtrace() ==
#0 /home/foo/tests/php/test4.php(13): foo()
#1 /home/foo/tests/php/test4.php(17): bar()
== getTrace() ==
#0 /home/foo/tests/php/test4.php(13): foo()
#1 /home/foo/tests/php/test4.php(17): bar()
== getTraceAsString() ==
#0 /home/foo/tests/php/test4.php(13): foo()
#1 /home/foo/tests/php/test4.php(17): bar()
#2 {main}
The only other place where I've seen {main} was with Xdebug. I guess it's some internal PHP stack frame, but why is it only visible when getting the trace as a string?