<?php
echo <<<EOT
<script language="javascript" type="text/javascript">
function switch_filedesc(id)
{
var el = document.getElementById(id);
if (el.style.display == 'none') {
el.style.display = 'block';
} else {
el.style.display = 'none';
}
}
function copytextToClipboard(txt)
{
if (window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData('Text', txt);
}
}
</script>
EOT;
class MyException extends Exception
{
// 重定义构造器使 message 变为必须被指定的属性
public function __construct($message, $code = 0) {
// 自定义的代码
// 确保所有变量都被正确赋值
parent::__construct($message, $code);
}
// 自定义字符串输出的样式 */
public function __toString() {
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}
public function customFunction() {
echo "A Custom function for this type of exception\n";
}
}
class TestException
{
public $var;
const THROW_NONE = 0;
const THROW_CUSTOM = 1;
const THROW_DEFAULT = 2;
function __construct() {
}
function aa($d)
{
throw new MyException('1 is an invalid parameter', 5);
}
}
try{
$dd=new TestException();
$dd->aa("aaa");
}
catch (MyException $ex) {
__error_dump_trace($ex);
}
function __error_dump_trace($ex)
{
echo '<strong>Exception: </strong>' . get_class($ex) . "<br />\n";
if ($ex->getMessage() != '') {
echo '<strong>Message: </strong>' . $ex->getMessage() . "<br />\n";
}
echo "<br />\n";
$trace = $ex->getTrace();
$ix = count($trace);
print_r($trace);
foreach ($trace as $point) {
$file = isset($point['file']) ? $point['file'] : null;
$line = isset($point['line']) ? $point['line'] : null;
$id = md5("{$file}({$line})");
$function = isset($point['class']) ? "{$point['class']}::{$point['function']}" : $point['function'];
$args = array();
if (is_array($point['args']) && count($point['args']) > 0) {
foreach ($point['args'] as $arg) {
switch (gettype($arg)) {
case 'array':
$args[] = 'array(' . count($arg) . ')';
break;
case 'resource':
$args[] = gettype($arg);
break;
case 'object':
$args[] = get_class($arg);
break;
case 'string':
if (strlen($arg) > 30) {
$arg = substr($arg, 0, 27) . ' ...';
}
$args[] = "'{$arg}'";
break;
default:
$args[] = $arg;
}
}
}
$args = implode(", ", $args);
echo <<<EOT
<hr />
<strong>Filename:</strong> <a href="javascript:switch_filedesc('{$id}');">{$file} [{$line}]</a><br />
#{$ix} {$function}($args)
<div id="{$id}" class="filedesc" style="display: none;">
ARGS:
EOT;
dump($point['args']);
echo "SOURCE CODE: <br />\n";
echo __error_show_source ($file, $line);
echo "\n</div>\n";
echo "<br />\n";
$ix--;
}
}
function __error_show_source($file, $line, $prev = 10, $next = 10)
{
if (!(file_exists($file) && is_file($file))) {
return '';
}
$data = file($file);
$count = count($data) - 1;
//count which lines to display
$start = $line - $prev;
if ($start < 1) {
$start = 1;
}
$end = $line + $next;
if ($end > $count) {
$end = $count + 1;
}
//displaying
$out = '<table cellspacing="0" cellpadding="0">';
for ($x = $start; $x <= $end; $x++) {
$out .= " <tr>\n";
if ($line != $x) {
$out .= " <td class=\"line-num\">";
} else {
$out .= " <td class=\"line-num-break\">";
}
$out .= str_repeat(' ', (strlen($end) - strlen($x)) + 1);
$out .= $x;
$out .= " </td>\n";
$out .= " <td class=\"source\"> ";
$out .= t($data[$x - 1]);
$out .= "</td>\n </tr>\n";
}
$out .= "</table>\n";
return $out;
}
function t($text)
{
return nl2br(str_replace(' ', ' ', htmlspecialchars($text)));
}
function dump($vars, $label = '', $return = false)
{
if (ini_get('html_errors')) {
$content = "<pre>\n";
if ($label != '') {
$content .= "<strong>{$label} :</strong>\n";
}
$content .= htmlspecialchars(print_r($vars, true));
$content .= "\n</pre>\n";
} else {
$content = $label . " :\n" . print_r($vars, true);
}
if ($return) { return $content; }
echo $content;
return null;
}
?>
发表于 @ 2008年07月14日 11:00:00|评论(loading...)|编辑|收藏