PHP Dump/Debug script.

Ever use PHP’s var_dump() or print_r() to debug what is going wrong with that $data you have ?

Well, this simple script acts as the above functions, yours first parameter is your data, and the second optional parameter is stoping the script or continuing on.

The ‘debug_backtrace()’ function will return which file call’s the dump function so you can easily track where your errors are coming from.

 
	function dump($data = array(), $finish = TRUE) {
 
		list($referrer) = debug_backtrace();
		$total = count($data);
		echo '<fieldset style="background: #fefefe !important; border:2px red solid; padding:5px">';
		echo '<legend style="background:lightgrey; padding:5px;">'.$referrer['file'].' @ line: '.$referrer['line'].'</legend>';
		echo '<pre>';
		$l = 0;
		if($data) {
			foreach($data as $line => $value) {
		        echo '<br /><strong>Debug #'.(++$l).' of '.$total.', Line: #'. $line .'</strong>:<br /> ';
				print_r($value);
			}
		}
		echo "

“;
echo “

“;
if($finish == TRUE) die;

}

This entry was posted in Code, fun, work and tagged , , , , , . Bookmark the permalink.

One Response to PHP Dump/Debug script.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">