... blabla blabla blabla */ $_DEBUG = Array(); for ($i = 0; $i < 10; $i++) $_DEBUG[$i] = Array(); global $_DEBUG; function ex_debug($str, $level=1) { global $_DEBUG; $_DEBUG[$level][] = $str; } $_INFO = Array(); global $_INFO; function ex_info($str) { global $_INFO; $_INFO[] = $str; } class Debug extends XMLement { function __construct() { parent::__construct('debug', NULL, 'debug'); global $_CONF, $_APPREQ, $_FORM, $_DEBUG, $_INFO; $level = $_CONF['debug_level']; $this->BuildStrings($_INFO, 'info'); if ($level >= 1) { $this->BuildArray($_GET, 'GET', 'php'); $this->BuildArray($_POST, 'POST', 'php'); $this->BuildArray($_FILES, 'FILES', 'php'); $this->BuildArray($_SESSION, 'SESSION', 'php'); $this->BuildStrings($_DEBUG[1], 'app'); } if ($level >= 2) { // Application-specific $this->BuildArray($_APPREQ, 'APPREQ', 'app'); $this->BuildArray($_CONF, 'CONF', 'app'); $this->BuildArray($_FORM, 'FORM', 'app'); $this->BuildStrings($_DEBUG[2], 'app'); } if ($level >= 3) $this->BuildStrings($_DEBUG[3], 'app'); if ($level >= 4) $this->BuildArray($_SERVER, 'SERVER', 'php'); } function BuildStrings($strarr, $type, $level=NULL) { if ($level == NULL) foreach ($strarr as $key => $value) { $element = $this->ForkChild('string', $value); $element->SetAttribute('type', $type); $this->AddChild($element); } } function BuildVariable($name, $value) { $element = $this->ForkChild('variable'); $element->AddElement('name', (string)$name); $element->AddElement('value', (string)$value); return $element; } function BuildArray($array, $name=NULL, $type=NULL, $parent=NULL) { if (!is_array($array)) { return false; } if (count($array) == 0) return false; $element = $this->ForkChild('array'); if ($name != NULL) $element->AddElement('name', $name); if ($type != NULL) $element->SetAttribute('type', $type); foreach ($array as $name => $value) { if ($this->BuildArray($value, $name, NULL, $element) == false) { if (is_array($value)) $value = 'Empty Array'; $variable = $this->BuildVariable($name, $value); $element->AddChild($variable); } } if ($parent == NULL) $this->AddChild($element); else $parent->AddChild($element); return true; } } // XXX: Temporary function backtrace($backtrace) { $output = "
\n"; $output .= "Backtrace:
\n"; // $backtrace = debug_backtrace(); foreach ($backtrace as $bt) { $args = ''; if (is_array($bt['args'])) foreach ($bt['args'] as $a) { if (!empty($args)) { $args .= ', '; } switch (gettype($a)) { case 'integer': case 'double': $args .= $a; break; case 'string': $a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : ''); $args .= "\"$a\""; break; case 'array': $args .= 'Array('.count($a).')'; break; case 'object': $args .= 'Object('.get_class($a).')'; break; case 'resource': $args .= 'Resource('.strstr($a, '#').')'; break; case 'boolean': $args .= $a ? 'True' : 'False'; break; case 'NULL': $args .= 'Null'; break; default: $args .= 'Unknown'; } } if (!array_key_exists('class', $bt)) $bt['class'] = ''; if (!array_key_exists('type', $bt)) $bt['type'] = ''; if (!array_key_exists('function', $bt)) $bt['function'] = ''; $output .= "
\n"; $output .= "file: {$bt['line']} - {$bt['file']}
\n"; $output .= "call: {$bt['class']}{$bt['type']}{$bt['function']}($args)
\n"; } $output .= "
\n"; return $output; } ?>