-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions_debug.php
155 lines (140 loc) · 3.57 KB
/
functions_debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
function vd($var)
{
echo "<pre>";
my_var_dump( $var );
echo "</pre>";
}
/** my_var_dump() is a substitute for the var_dump PHP fonction.
* It uses a marking algorithm to know which references it has allready
* visited. It creates unique ids so that you may understand where thoses
* allready visited references were displayed.
*
* @param $var the var to dump
* @param $unsetAll true if you wish to unset all the labeled ids
* @param $links true if you wish to display links between referees and
* references
*/
function my_var_dump($var, $unsetAll = true, $links = true)
{
_my_var_dump_aux($var, $links);
if ($unsetAll) _unset_all_var_dump($var);
}
function _generateId($isArray)
{
static $idArrays = 0;
static $idObjects = 0;
if ($isArray)
return 'ARR_'.$idArrays++;
else return 'OBJ_'.$idObjects++;
}
function _my_var_dump_aux($var, $links = true)
{
// print '<pre>';
if ((is_array($var) && isset($var["VAR_DUMP_NAME"]))
|| (is_object($var) && isset($var->___var_dumped)))
{
$id = (is_array($var) ? $var["VAR_DUMP_NAME"]
: $var->___var_dumped);
if ($links)
print('<b><a href="#'.$id.'">Ref '.$id.'</a></b>');
else
print('<b>Ref '.$id.'</b>');
}
else
{
if (is_array($var))
{
$id = _generateId(true);
$size = sizeof($var);
print '<b><a name="'.$id.'">'.$id.'</a></b> array[<b>'.$size.'</b>]';
print '<table border=1 cellspacing=0 cellpadding=3>';
// LL print ' ) {';
$var["VAR_DUMP_NAME"] = $id;
reset($var);
$index = 1;
foreach ($var as $key => $value)
{
if (is_int($key) || $key != "VAR_DUMP_NAME")
{
print '<tr bgcolor=#D0D0D0><td>';
// LL print('<dir>');
print('"'.$key.'" </td>'.(is_array($var[$key])?'<td colspan="2">':'<td>').' ');
// LL print('"'.$key.'" => ');
if ($var[$key] == null)
print('NULL');
else
_my_var_dump_aux($var[$key], $links);
if ($index < $size) print('');
// LL if ($index < $size) print(',');
print '</td></tr>';
// LL print('</dir>');
}
$index++;
}
print( '</table>' );
// LL print('}');
}
else if (is_object($var))
{
$id = _generateId(false);
$var->___var_dumped = $id;
print('<b><a name="'.$id.'">'.$id.'</a></b> object('.get_class($var).') {');
print '<table border=5 cellspacing=0 cellpadding=3>';
foreach ($var as $key => $value)
{
if ($key != "VAR_DUMP_NAME")
{
print '<tr><td>';
// LL print('<dir>');
print('-> '.$key.' </td><td> ');
// LL print('->'.$key.' = ');
if (!isset($var->$key))
print('NULL');
else
_my_var_dump_aux($var->$key, $links);
print '</td></tr>';
// LL print('</dir>');
}
}
print( '</table>' );
// print('}');
}
else
{
ob_start();
var_dump($var);
$str = ob_get_contents();
ob_end_clean();
$str = ereg_replace( "(string\([^\)]+\) )(.*)", "\\1</td><td>\\2", $str );
$str = ereg_replace( "(bool)\(([^\)]+)\)", "\\1</td><td>\\2", $str );
$str = ereg_replace( "(int)\(([^\)]+)\)", "\\1</td><td>\\2", $str );
print $str;
}
}
// LL print '</pre>';
}
function _unset_all_var_dump($var)
{
if (is_array($var) && isset($var["VAR_DUMP_NAME"]))
{
unset($var["VAR_DUMP_NAME"]);
reset($var);
foreach ($var as $key => $value)
{
if ((is_int($key) || $key != "VAR_DUMP_NAME")
&& $var[$key] != null)
_unset_all_var_dump($var[$key]);
}
}
else if (is_object($var) && isset($var->___var_dumped))
{
unset($var->___var_dumped);
foreach ($var as $key => $value)
{
if ($key != "VAR_DUMP_NAME" && isset($var->$key))
_unset_all_var_dump($var->$key);
}
}
}
?>