Proper use of the PHP function debug_backtrace ();
The PHP function debug_backtrace ( ); is very useful, but it can be dangerous. A beginning developer trying to find a bug on a production-line website might be inclined to use print_r ( ); to show what debug_backtrace ( ); returns, as it returns data in the format of an array.
The function print_r ( ); displays things directly into the screen. That may not be very wise for a production-line website. After a little thinking, I came up with a secure way to view backtraces. It’s an easy one-line piece of code that can be inserted into a PHP (5) script.
file_put_contents (‘backtrace.txt’, print_r (debug_backtrace (), true));
Posted in PHP | View Comments