Re: Backtrace in fatal error?
| From: | Richard Quadling | Date: | Wed, 01 Sep 2010 10:30:46 +0000 |
| Subject: | Re: Backtrace in fatal error? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307802@lists.php.net to get a copy of this message | ||
On 31 August 2010 09:49, Paul Freeman <freeman3@centrum.cz> wrote:
> When fatal error occurs is it possible to output also the backtrace in the error log? The
> simple error message with file line
> only is quite useless...
<?php
namespace baz;
set_error_handler(
function($ErrNo, $ErrStr, $ErrFile, $ErrLine, $ErrContext){
echo 'An error occurred.', PHP_EOL;
var_export(debug_backtrace(true));
// Allow PHP to continue executing.
return false;
},
-1
);
register_shutdown_function(
function(){
echo 'We died a terrible death.';
var_export(debug_backtrace(true));
}
);
function bar() {
echo 'In ', __FUNCTION__, PHP_EOL;
echo 1 / 0; // Divide by zero warning.
foo();
}
function foo() {
echo 'In ', __FUNCTION__, PHP_EOL;
$a = \SNAFU; // Fatal error
}
bar();
?>
outputs ...
In baz\bar
An error occurred.
array (
0 =>
array (
'file' => 'Z:\\bad.php',
'line' => 24,
'function' => 'baz\\{closure}',
'args' =>
array (
0 => 2,
1 => 'Division by zero',
2 => 'Z:\\bad.php',
3 => 24,
4 =>
array (
),
),
),
1 =>
array (
'file' => 'Z:\\bad.php',
'line' => 33,
'function' => 'baz\\bar',
'args' =>
array (
),
),
)
Warning: Division by zero in Z:\bad.php on line 24
In baz\foo
Fatal error: Undefined constant 'SNAFU' in Z:\bad.php on line 30
We died a terrible death.array (
0 =>
array (
'function' => 'baz\\{closure}',
'args' =>
array (
),
),
)
So, it looks like extension or a core mod only.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY