Data[] = Array('value' => $varValue, 'debug_type' => 'var_dump'); } } function prepareHTML($dataIndex) { $Data =& $this->Data[$dataIndex]; if($Data['debug_type'] == 'html') return $Data['html']; switch($Data['debug_type']) { case 'error': $fileLink = $this->getFileLink($Data['file'],$Data['line']); $ret = ''.$this->getErrorNameByCode($Data['no']).': '.$Data['str']; $ret .= ' in '.$fileLink.' on line '.$Data['line'].''; return $ret; break; case 'var_dump': $ret = highlight_string('', true); $ret = preg_replace('/<\?php (.*)\?>/s','$1',$ret); return $ret; break; case 'trace': $trace =& $Data['trace']; $i = 0; $traceCount = count($trace); $ret = ''; while($i < $traceCount) { $traceRec =& $trace[$i]; $argsID = 'trace_args_'.$dataIndex.'_'.$i; $ret .= 'Function: '.$this->getFileLink($traceRec['file'],$traceRec['line'],$traceRec['class'].$traceRec['type'].$traceRec['function']).''; $ret .= ' in '.basename($traceRec['file']).' on line '.$traceRec['line'].'
'; // ensure parameter value is not longer then 200 symbols foreach ($traceRec['args'] as $argID => $argValue) { if( strlen($argValue) > 200 ) $traceRec['args'][$argID] = substr($argValue,0,50).' ...'; } $args = highlight_string('', true); $args = preg_replace('/<\?php (.*)\?>/s','$1',$args); $ret .= ''; $i++; } /*$ret = highlight_string('', true); $ret = preg_replace('/<\?php (.*)\?>/s','$1',$ret);*/ return $ret; break; default: return 'incorrect debug data'; break; } } function getFileLink($file, $lineno = 1, $title = '') { if(!$title) $title = $file; return ''.$title.''; } function getLocalFile($remoteFile) { return str_replace(DOC_ROOT, WINDOWS_ROOT, $remoteFile); } function appendTrace() { $trace = debug_backtrace(); array_shift($trace); $this->Data[] = Array('trace' => $trace, 'debug_type' => 'trace'); } function appendHTML($html) { $this->Data[] = Array('html' => $html,'debug_type' => 'html'); } function getErrorNameByCode($errorCode) { switch($errorCode) { case E_USER_ERROR: return 'Fatal Error'; break; case E_WARNING: case E_USER_WARNING: return 'Warning'; break; case E_NOTICE: case E_USER_NOTICE: return 'Notice'; break; default: return ''; break; } } /** * Generates report * */ function printReport() { $i = 0; $lineCount = count($this->Data); ?> error ['.$errno.'] = ['.$errstr.']
'; $errorType = $this->getErrorNameByCode($errno); if( substr($errorType,0,5) == 'Fatal') { $this->printReport(); exit; } if(!$errorType) { trigger_error('Unknown error type ['.$errno.']', E_USER_ERROR); return false; } $this->Data[] = Array('no' => $errno, 'str' => $errstr, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext, 'debug_type' => 'error'); } } $debugger = new Debugger(); set_error_handler( array(&$debugger,'saveError') ); register_shutdown_function( array(&$debugger,'printReport') ); ?>