I tryed to email me debug_backtrace() but it just prints out the array.
I need to assign it to a variable so that var_export can work with it.
How can i do that?
7 Answers
There is a function that "prints out the array", debug_print_backtrace. You didn't mix those two up by any chance?
And both var_export() and print_r() by default print the result. You have to pass true as the second parameter if you want them to return the result (so you can assign it to a variable)
$result = var_export(debug_backtrace(), true);
Comments
Send the following $msg :
$msg = print_r( debug_backtrace( ) , true ) ;
Not tested, but that's one way.
1 Comment
I know this is old, but I found myself with the same problem. I can't confirm 100%, but it seems very likely that it relates to an out-of-memory error.
My scenario - on 3rd-party submission failure, send an email with debugging information (namely, where code failed). I too was saving $trace = debug_backtrace() to a variable and then later using var_export($trace, true) to embed it within an email. I'm using this helper function both inside the CodeIgniter framework and on a standalone page (legacy code).
The backtrace + export code worked fine in the standalone page, but printed (partial) results to the screen when in CodeIgniter. It actually only printed the first 2 traces before cutting off in the middle of a line.
When instead of echoing the whole backtrace, I only printed the line, file, fn, and args, everything worked fine.
My guess is that too much recursion from backtrace (marching through the CI objects) blew out memory, thus causing it to vomit the results to screen.
1 Comment
object element from each level. During my tests, that included the God-like $this object which includes everything + the kitchen sink + a circular reference error.