Location: PHPKode > scripts > MDS Debug > mds-debug/debug.class.php
<?
/************************************************************
* DUMP ENGINE
*
****************/

//prints dump of variable
function dump_($var)
{
 	static $level;
 	if(!isSet($level)) $level=0;
	
	if(!isSet($var))
	{
		echo '<font color=#880000>NOT SET</font><br>';
	}
	elseif(is_null($var))
	{
		echo '<font color=#880000>NULL</font><br>';
	}
	elseif(is_array($var) || is_object($var))
	{
		echo '<font color=#888800><b>' . (is_array($var) ? 'Array[' . count($var) . ']' : 'Object') . '</b></font><br>';
		$level++;
		foreach($var as $key=>$value)
		{
			echo '<nobr>' . str_repeat('<b>.</b>........', $level);
			echo '<b>[' . $key . ']</b>=';
			if($key==="GLOBALS") 
			{
				echo '<font color=#FF0000><b>ITTERATION</b></font><br>';
				continue;	
			} 
			dump_($value);
			echo '</nobr>';				
		}
		/* if object print function list */
		if(is_object($var)) 
		{
			$value=get_class_methods($var);
			echo str_repeat('<b>.</b>........', $level).'<font color=#FF0000><b>CLASS METHODS</b></font> ';
			dump_($value);	
		}
		/* if object print function list */
		$level--;
		
	}
	elseif(is_string($var))
	{
		$varlen=strlen($var);
		$var=htmlspecialchars($var);
		$var=str_replace("\r",'<span style="padding-right: 10px; border: 1px solid red; font-size: 1px;">&nbsp;</span> ',$var);
		$var=str_replace("\n",'<span style="padding-right: 10px; border: 1px solid navy; font-size: 1px;">&nbsp;</span><br>' . str_repeat('<b>.</b>.....', $level),$var);
		$var=str_replace("\t",'<span style="padding-right: 20px; border: 1px solid tan; font-size: 1px;">&nbsp;</span> ',$var);
		echo '[' . $var . '] <font color=#008800><b>of ';
		if(is_numeric($var)) echo 'NUMERIC ';
		echo 'STRING[' . $varlen . ']</b></font><br>';
	}
	elseif(is_bool($var))
	{
		if($var) echo 'TRUE <b>of BOOLEAN</b><br>'; else echo 'FALSE <b>of BOOLEAN</b><br>';
	}
	elseif(is_resource($var))
	{
		echo $var . ' <font color=#880088><b>of RESOURCE (' . get_resource_type($var) . ')</b></font><br>';		
	}
	else
	{
		echo $var . ' <font color=#000088><b>of ' . strtoupper(gettype($var)) . '</b></font><br>';
	}
	
}

function dump($var, $varname='', $file='', $line='')
{
	?><div style="background: #efefef; border: 1px solid black; padding: 10px;"><?
	if(!empty($varname) || !empty($file) || !empty($line)) echo '<b>Dump </b>';
	if(!empty($varname)) echo " <b>of variable: $varname</b>";
	if(!empty($file)) echo " <b>in $file</b>";
	if(!empty($line)) echo " <b>on line $line</b>";
	echo '<br>';
	dump_($var);
	?></div><?
}

/************************************************************
* PROFILER ENGINE
* 
****************/

//get start time
function pf_start()
{
    list($msec, $sec)=explode(' ', microtime());
    return (float)$msec+(float)$sec;
}

//calculate total time in SECONDS
function pf_show($pfInstance)
{
    list($msec, $sec)=explode(' ', microtime());
    return (float)$msec+(float)$sec-$pfInstance;
}

function pf_stop(&$pfInstance)
{
	$timer=pf_show($pfInstance);
	$pfInstance=null;
	return $timer;
}


/************************************************************
* ERROR HANDLER ENGINE
* 
****************/

function mode($mode='', $logdir='')
{
	error_reporting(E_ALL | (defined('E_STRICT')? E_STRICT : 0));
	ini_set("log_errors_max_len", 10000);
	
	$logdir=(!empty($logdir)) ? realpath($logdir) : realpath('.');
	$logdir.= '/' . date('d.m.Y') . '.log';
	ini_set("error_log", $logdir);
	
	switch($mode)
 	{
		case "DEBUG":
			ini_set("log_errors",1);				
			ini_set("display_errors",1);
			
			break;
		default:
		case "NORMAL":
			ini_set("log_errors",1);
			ini_set("display_errors",0);
			break;
		case "SILENT":
			ini_set("log_errors",0);
			ini_set("display_errors",0);
			break;
	}
}
?>
Return current item: MDS Debug