Location: PHPKode > scripts > DHTMLDump > dhtmldump/class/class.dhtmldump.php
<?php
	
	class DHTMLDump {
		
		private static function dumpChunk ($objTreeOrFolder, $mChunk, $iLevel, $iMaxDepth){
			
			if (is_bool($mChunk)){
				return ($mChunk ?'true':'false').' (Boolean)';
			}
			elseif (is_int($mChunk)){
				return "$mChunk (Integer)";
			}
			elseif (is_float($mChunk)){
				return "$mChunk (Float)";
			}
			elseif (is_string($mChunk)){
				return "'".htmlentities($mChunk)."' (String length=".strlen($mChunk).")";
			}
			elseif (is_array($mChunk)){
				if ($iLevel < $iMaxDepth){
					
					ksort($mChunk);
					
					foreach($mChunk as $mKey => $mValue){
						if ($mKey === 'GLOBALS'){ //the three equals are ok... otherwise, we get bad comparison because of casting
							$objTreeOrFolder->addFolder ('['.self::dumpChunk($objTreeOrFolder, $mKey,$iLevel+1,$iMaxDepth).'] => array (*RECURSION)');
						}
						elseif (is_array($mValue)){
							$iKey = $objTreeOrFolder->addFolder ("[$mKey] => array (".count($mValue).' elements)');
							self::dumpChunk($objTreeOrFolder->getObjFolder($iKey), $mValue, $iLevel +1, $iMaxDepth);
						}
						elseif (is_object($mValue)){
							$iKey = $objTreeOrFolder->addFolder ("[$mKey] => ".get_class($mValue));
							self::dumpChunk($objTreeOrFolder->getObjFolder($iKey), $mValue, $iLevel +1, $iMaxDepth);
						}
						else {
							$objTreeOrFolder->addDocument("[$mKey] => ".self::dumpChunk($objTreeOrFolder, $mValue,$iLevel,$iMaxDepth));
						}
					}
				}
			}
			elseif (is_object($mChunk)){
				
				if ($iLevel < $iMaxDepth){
					//converting the object to an array for easy parsing
					$mChunk = (array) $mChunk;
					$mChunkToBeSorted = array ();
					foreach ($mChunk as $mKey => $mValue){
						$a_test = explode ("\0",$mKey);
						if (count ($a_test) == 1){
							$mChunkToBeSorted [$a_test[0].':public'] = $mValue;
						}
						else if ($a_test [1] == '*'){
							$mChunkToBeSorted [$a_test[2].':protected'] = $mValue;
						}
						else {
							$mChunkToBeSorted [$a_test[2].':private'] = $mValue;
						}
					}
					
					ksort($mChunkToBeSorted);
					
					foreach($mChunkToBeSorted as $mKey => $mValue){
						
						if (is_array($mValue)){
							$iKey = $objTreeOrFolder->addFolder ("[$mKey] => array (".count($mValue).' elements)');
							self::dumpChunk($objTreeOrFolder->getObjFolder($iKey), $mValue, $iLevel +1,$iMaxDepth);
						}
						elseif (is_object($mValue)){
							$iKey = $objTreeOrFolder->addFolder ("[$mKey] => object ".get_class($mValue));
							self::dumpChunk($objTreeOrFolder->getObjFolder($iKey), $mValue, $iLevel +1,$iMaxDepth);
						}
						else {
							$objTreeOrFolder->addDocument("[$mKey] => ".self::dumpChunk($objTreeOrFolder, $mValue,$iLevel,$iMaxDepth));
						}
					}
				}
			}
			elseif (is_resource($mChunk)){
				return "resource (".get_resource_type($mChunk).")";
			}
			elseif (is_null($mChunk)){
				return 'null';
			}
		}
		
		public static function dumpVariable ($mVariable, $iWidth=0, $iHeight=0, $iMaxDepth=7){
			$objTreeview = new CLASS_Treeview();
			
			if (is_array($mVariable)){
				$iKey = $objTreeview->addFolder ('array ('.count($mVariable).' elements)');
				self::dumpChunk($objTreeview->getObjFolder($iKey), $mVariable, 1, $iMaxDepth);
			}
			elseif (is_object($mVariable)){
				$iKey = $objTreeview->addFolder (get_class($mVariable));
				self::dumpChunk($objTreeview->getObjFolder($iKey), $mVariable, 1, $iMaxDepth);
			}
			else if (is_null($mVariable)){
				$iKey = $objTreeview->addFolder ('null');
			}
			else {
				$objTreeview->addDocument(self::dumpChunk($objTreeview, $mVariable,0));
			}
			return $objTreeview->render($iWidth,$iHeight);
		}
	}
?>
Return current item: DHTMLDump