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)."<br>";
echo $t."\tattributes(".count(get_class_vars($class))."<br>";
$this->pass_array(get_object_vars($object), $depth+1);
echo $t."\tmethods(".count(get_class_methods($class))."<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).'<br>';
$this->pass_array($value, $depth+1);
}
else
{
if(is_object($value))
{
$class = get_class($value);
echo $t.' ['.$key.'] => '.gettype($value).'('.strlen($class).' "'.$class.'"<br>';
$this->pass_object($value, $class, $depth);
}
else
{
echo $t.' ['.$key.'] => '.gettype($value).'('.strlen($value).' "'.$value.'"<br>';
}
}
}
echo "$t}<br>";
}
public function show ($name, $var, $file="", $line="" {
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).' "'.$class.'"<br>';
$this->pass_object($var);
}
else
{
echo gettype($var).'('.strlen($var).' "'.$var.'"';
}
echo "</div></pre>";
}
}
}
?>