public function dump(&$thevariable, $thehtmlflag = null) { if ($thehtmlflag === null) { if (empty($this)) { $thehtmlflag = !empty($_SERVER['DOCUMENT_ROOT']); } else { if (is_subclass_of($this, "sdd")) { $thehtmlflag = $this->m_htmlflag; } else { $thehtmlflag = !empty($_SERVER['DOCUMENT_ROOT']); } } } switch (gettype($thevariable)) { case 'array': return SDD::dArray($thevariable, $thehtmlflag); case 'object': return SDD::dObject($thevariable, $thehtmlflag); default: return SDD::scalar($thevariable, $thehtmlflag); } }
/** * Dump the contents of an object. * * Provide a structured display of an object and all the * classes from which it was derived. The contents of * the object is displayed from most derived to the base * class, in order. * * @param object $theObject the object to be dumped. * @param boolean $theHTMLFlag true if HTML is to be generated. * @return string the display form of the object. */ function dObject(&$theObject, $theHTMLFlag) { $theObjectVars = get_object_vars($theObject); // // Get the inheritance tree starting with the object and going // through all the parent classes from there. // $theClass = get_class($theObject); $theClasses[] = $theClass; while ($theClass = get_parent_class($theClass)) { $theClasses[] = $theClass; } // // Get all the class variables for each class in the inheritance // tree. There will be some duplication, but we'll sort that out // in the output process. // foreach ($theClasses as $theClass) { $theClassVars[$theClass] = get_class_vars($theClass); } // // Put the inheritance tree from base class to most derived order // (this is how we get rid of duplication of the variable names) // Go through the object variables starting with the base class, // capture the output and delete the variable from the object // variables. // $theClasses = array_reverse($theClasses); $theOutput = array(); foreach ($theClasses as $theClass) { $theOutput[$theClass] = array(); foreach ($theClassVars[$theClass] as $theVariable => $value) { if (array_key_exists($theVariable, $theObjectVars)) { if (is_array($theObjectVars[$theVariable])) { $theOutput[$theClass][] = $theVariable . " = " . SDD::dArray($theObjectVars[$theVariable], $theHTMLFlag); } else { if (is_object($theObjectVars[$theVariable])) { $theOutput[$theClass][] = $theVariable . " = " . SDD::dObject($theObjectVars[$theVariable], $theHTMLFlag); } else { $theOutput[$theClass][] = $theVariable . " = " . ($theHTMLFlag ? preg_replace('|<|s', '<', var_export($theObjectVars[$theVariable], true)) : var_export($theObjectVars[$theVariable], true)); } } unset($theObjectVars[$theVariable]); } } } // // Put the classes back in most derived order for generating printable // output. // $theClasses = array_reverse($theClasses); if ($theHTMLFlag) { $theString = "<table>\n<thead>\n"; foreach ($theClasses as $theClass) { $theString .= "<th>\n{$theClass}\n</th>\n"; } $theString .= "</thead>\n<tr valign=top>\n"; foreach ($theClasses as $theClass) { $theString .= "<td>\n<table border=1>\n"; foreach ($theOutput[$theClass] as $theVariableOutput) { $theString .= "<tr>\n<td>\n{$theVariableOutput}\n</td>\n</tr>\n"; } $theString .= "</table>\n</td>\n"; } $theString .= "</tr>\n</table>\n"; } else { $classIndent = ""; $classDataIndent = " "; $theString = ""; foreach ($theClasses as $theClass) { $theString .= "{$classIndent}class {$theClass}\n\n"; foreach ($theOutput[$theClass] as $theVariableOutput) { $theString .= "{$classDataIndent}{$theVariableOutput}\n"; } $theString .= "\n"; $classIndent .= " "; $classDataIndent .= " "; } } return $theString; }