Webstatt.org - Community seit 2006 - 2012 (2024?)

Debug Klasse

Avatar user-287
30.03.2007 10:44

Debug Klasse v.0.1
Eine Debug-Klasse, mit der man einfach den Inhalt von Variablen auslesen kann.

Variablen kann man so debuggen:

$debug->get(); // Alle $_GET Variablen

$test12 = "Hallo"
$debug->test12($test12); // Eigene Variable



<?PHP

class debug {

public $debug_mode;

public function __construct($debug_mode = false) {
$this->debug_mode = $debug_mode;
if($this->debug_mode) echo "<h5>DEBUG MODE = ON</h5>";
}

/* TAB */
protected function t ($depth=0)
{
$t = "";

for($i=0; $i<$depth; $i++)
{
$t .= "\t";
}

return $t;
}

/* Debugged ein Objekt */
protected function pass_object($object, $class=null, $depth=0)
{
if($class == null) $class = get_class($object);

$t = $this->t($depth);

if(get_parent_class($class)) echo $t."\tparent_class(".get_parent_class($class)."zwinkern<br>";

echo $t."\tattributes(".count(get_class_vars($class))."zwinkern<br>";
$this->pass_array(get_object_vars($object), $depth+1);

echo $t."\tmethods(".count(get_class_methods($class))."zwinkern<br>";
$this->pass_array(get_class_methods($class), $depth+1);
}

/* Debugged einen Array */
protected function pass_array($array, $depth=0)
{
$t = $this->t($depth);

echo "$t{<br>";
foreach($array as $key => $value)
{
if(is_array($value))
{
echo $t.' ['.$key.'] => '.gettype($value).'('.count($value).'zwinkern<br>';
$this->pass_array($value, $depth+1);
}
else
{
if(is_object($value))
{
$class = get_class($value);
echo $t.' ['.$key.'] => '.gettype($value).'('.strlen($class).'zwinkern "'.$class.'"<br>';
$this->pass_object($value, $class, $depth);
}
else
{
echo $t.' ['.$key.'] => '.gettype($value).'('.strlen($value).'zwinkern "'.$value.'"<br>';
}
}
}
echo "$t}<br>";
}

public function show ($name, $var, $file="", $line=""zwinkern {
if($this->debug_mode)
{
if(!empty($file)) $file = ' [FILE: '.$file.']';
if(!empty($line)) $line = ' [LINE: '.$line.']';

echo '<pre><div style="margin-top:20px;"><b>'.$name.'</b>'.$line.$file.'</div>';
echo '<div>';
if(is_array($var))
{
$this->pass_array($var);
}
elseif(is_object($var))
{
$class = get_class($var);
echo gettype($var).'('.strlen($class).'zwinkern "'.$class.'"<br>';
$this->pass_object($var);
}
else
{
echo gettype($var).'('.strlen($var).'zwinkern "'.$var.'"';
}
echo "</div></pre>";
}
}


}

?>