Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog.

Archive for March, 2009

dumping php array data and debug_print_backtrace to a log

Posted by chris on March 17th, 2009 Comments(0)

By default you cannot write a print_r, var_dump, or debug_print_backtrace to a log in PHP. When you call these methods, PHP immediately echo’s out the data. Instead you must use PHPs ob_start which instructs PHP to not output anything from the script. To access the contents of the buffer use ob_get_contents and to let PHP know its okay to output from your script once again call ob_end_clean.

1
2
3
4
	ob_start();
	var_dump(debug_backtrace());
	$backtrace=ob_get_contents();
	ob_end_clean();
In rant ()

using php debug_print_backtrace for debugging code

Posted by chris on March 4th, 2009 Comments(0)

This is a built-in PHP function that I can’t believe I didn’t learn about until just a few weeks ago. One of the developers at work was debugging an application that had a lot of includes and he called debug_print_backtrace(). It dumps out a nice array showing which files called a function, and what line number it occurs on.

See http://us2.php.net/debug_print_backtrace for more information.

In php ()