Improved object printing by including private/protectec/static members and constants. It is implemented by using PHP Reflection.

This commit is contained in:
maliayas 2012-01-25 05:20:53 +02:00
parent d9519d43f7
commit 098ff42bdd

View file

@ -2,6 +2,7 @@
/*********************************************************************************************************************\
* LAST UPDATE
* ============
* Jan 25, 2012 by maliayas
* Sep 29, 2011 by maliayas
* July 25, 2011 by maliayas
* March 22, 2007
@ -123,10 +124,10 @@ class dBug {
}
//create the table row header
function makeTDHeader($type,$header) {
function makeTDHeader($type,$header, $title = '') {
$str_d = ($this->bCollapsed) ? " style=\"display:none\"" : "";
echo "<tr".$str_d.">
<td valign=\"top\" onClick='dBug_toggleRow(this)' class=\"dBug_".$type."Key\">".$header."</td>
<td valign=\"top\" onClick='dBug_toggleRow(this)' class=\"dBug_".$type."Key\"" . (! empty($title) ? ' title="' . htmlspecialchars($title) . '"' : '') . ">".$header."</td>
<td>";
}
@ -223,32 +224,64 @@ class dBug {
$this->makeTableHeader("object","object");
if(is_object($var)) {
$arrObjVars=get_object_vars($var);
foreach($arrObjVars as $key=>$value) {
$value=(!is_object($value) && !is_array($value) && trim($value)=="") ? "[empty string]" : $value;
$this->makeTDHeader("object",$key);
$varRef = new ReflectionObject($var);
$props = $varRef->getProperties();
foreach($props as $prop) {
$prop->setAccessible(true);
$propValue = $prop->getValue($var);
$propName = $prop->getName();
$propModifiers = implode(' ', Reflection::getModifierNames($prop->getModifiers()));
$propAttr = $prop->isPublic() ? '+' : ($prop->isPrivate() ? '-' : '#');
$propAttr = '[' . $propAttr . ($prop->isStatic() ? 'S' : '') . '] ';
$propValue=(gettype($propValue) == "string" && trim($propValue)==="") ? "[empty string]" : $propValue;
$this->makeTDHeader("object",$propAttr . $propName, $propModifiers);
//check for recursion
if(is_object($value)||is_array($value)) {
$var_ser = serialize($value);
if(is_object($propValue)||is_array($propValue)) {
$var_ser = serialize($propValue);
if(in_array($var_ser, $this->arrHistory, TRUE)) {
$value = (is_object($value)) ? "*RECURSION* -> $".get_class($value) : "*RECURSION*";
$propValue = (is_object($propValue)) ? "*RECURSION* -> $".get_class($propValue) : "*RECURSION*";
}
}
if(in_array(gettype($value),$this->arrType))
$this->checkType($value);
else echo htmlspecialchars($value);
if(in_array(gettype($propValue),$this->arrType))
$this->checkType($propValue);
else echo htmlspecialchars($propValue);
echo $this->closeTDRow();
}
$arrObjMethods=get_class_methods(get_class($var));
foreach($arrObjMethods as $key=>$value) {
$this->makeTDHeader("object",$value);
echo "[function]".$this->closeTDRow();
$consts = $varRef->getConstants();
foreach($consts as $key => $const) {
$const=(gettype($const) == "string" && $const === "") ? "[empty string]" : $const;
$this->makeTDHeader("object",'[C] ' . $key);
echo htmlspecialchars($const);
echo $this->closeTDRow();
}
$methods = $varRef->getMethods();
foreach($methods as $method) {
$method->setAccessible(true);
$methodName = $method->name;
$methodModifiers = implode(' ', Reflection::getModifierNames($method->getModifiers()));
$methodAttr = $method->isPublic() ? '+' : ($method->isPrivate() ? '-' : '#');
$methodAttr = '[' . $methodAttr
. ($method->isStatic() ? 'S' : '')
. ($method->isAbstract() ? 'A' : '')
. ($method->isFinal() ? 'F' : '') . '] ';
$this->makeTDHeader("object", $methodAttr . $methodName, $methodModifiers);
echo htmlspecialchars('[method]');
echo $this->closeTDRow();
}
} else {
echo "<tr><td>".$this->error("object").$this->closeTDRow();
}
else echo "<tr><td>".$this->error("object").$this->closeTDRow();
array_pop($this->arrHistory);
echo "</table>";
}