Debugging your PHP Project

For years we have been utilizing a small class that allows us to easily debug PHP applications.  All you need to do is add your IP to the $ips array in the debug::enabled() function.

This script uses backtrace, which may not be available to you, to look-up the file and line of where debug::print_r() was called.  It then prints out that information, along with the variable passed to the function.

Usage:


/*
* @param mixed $obj - the variable to display
* @param bool $exit - calls exit() after print_r, default = false
* @param string $file - a fallback for environments without backtrace - use __FILE__
* @param string $line - a fallback for environments without backtrace - use __LINE__
* @param bool $print_pre - use <pre> to display the $obj, default = true
*/
debug::print_r($obj, $exit = false, $file = null, $line = null, $print_pre = true); // echo's result
debug::enabled(); // return bool (see array of IP's in debug.php.txt)

You may download the script from here (links to a .txt file): debug.php.txt.

The WordPress plugin can be found here: debug-print-r.

Leave a Reply

Your email address will not be published. Required fields are marked *