PHP_Debug : A PHP open source debug library

» Installation instructions

With PEAR

From the comand line

	> pear install PHP_Debug
	

Copy the css/js/images folders of /your_pear_root/data/PHP_Debug in your project directory

Then you will have to modify the path of these resources in the debug options (check PHP_Debug_HTML_Div_test.php)

Standalone

Dezip the package, the 3 tests should work without any modifications, except for the view source fonctionnality where you will have to modify the options in 'PHP_Debug_ShowSource.php'(CSS_ROOT, ALLOWED_PATH, PEAR_ROOT)

PS: If PEAR is already in the path you can comment the "set_include_path" line

When you create your PHP_Debug object, don't forget to setup the path ot the view source path, default is "./PHP_Debug_ShowSource.php"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
<?php
    /**
     * Options  array for Debug object
     */ 
    static private Array = array(
        'DEBUG_restrict_access'      => false,
        'DEBUG_allow_url_access'     => true,
        'DEBUG_url_key'              => 'pdw',
        'DEBUG_url_pass'             => 'pdw',
        'DEBUG_enable_watch'         => false,
        'DEBUG_replace_errorhandler' => true,
        'DEBUG_lang'                 => 'FR',
        'HTML_TABLE_view_source_script_name' => 'PHP_Debug_ShowSource.php',
        'HTML_TABLE_view_source_excluded_template' => array('')
    );
?>

Hello World !

(click here)

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
<?php
 
/**
 * Minimal test
 * 
 * @package PHP_Debug
 * @filesource
 * 
 * @version    CVS: $Id: PHP_Debug_test.php,v 1.1 2008/05/02 14:26:37 c0il Exp $
 */ 
 
header('Content-type: text/html; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">     
  <head>  
    <title>PEAR::PHP_Debug, Hello World !</title>
<?php
 
// Options array for Debug object
$options = array(
    'HTML_DIV_images_path' => 'images', 
    'HTML_DIV_css_path' => 'css', 
    'HTML_DIV_js_path' => 'js',
);
 
/**
 * Include Debug Class
 */ 
include_once('PHP/Debug.php');
 
// Debug object
$Dbg = new PHP_Debug($options);
 
?>
    <script type="text/javascript" src="<?php echo $options['HTML_DIV_js_path']; ?>/html_div.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="<?php echo $options['HTML_DIV_css_path']; ?>/html_div.css" />
  </head>
  <body>
  <div>
    <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
  </div>
<?php
 
echo '<div><h1>PEAR::PHP_Debug, Hello World !</h1></div>';
$Dbg->add('DEBUG INFO');
$Dbg->display();
 
?>
  </body>
</html>

Full example

(click here)

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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
 
/**
 * Test script for PHP_Debug 2.1.0 and the HTML_Div renderer
 * 
 * @package PHP_Debug
 * @author  COil
 * @since V2.1.0 - 6 apr 2006
 * @filesource
 * 
 * @version    CVS: $Id: PHP_Debug_HTML_Div_test.php,v 1.4 2009/01/12 21:13:00 c0il Exp $
 */
 
error_reporting(E_ALL); // Report all possible errors
//session_start();        // Start session
 
 
// Options array for Debug object
$options = array(
    'render_type'          => 'HTML',    // Renderer type
    'render_mode'          => 'Div',     // Renderer mode
    'restrict_access'      => false,     // Restrict access of debug
    'allow_url_access'     => true,      // Allow url access
    'url_key'              => 'key',     // Url key
    'url_pass'             => 'nounou',  // Url pass
    'enable_watch'         => false,     // Enable wath of vars
    'replace_errorhandler' => true,      // Replace the php error handler
    'lang'                 => 'FR',      // Lang
 
    // Renderer specific
    'HTML_DIV_view_source_script_name' => 'PHP_Debug_ShowSource.php',
    'HTML_DIV_remove_templates_pattern' => true,
    'HTML_DIV_templates_pattern' => 
        array(
            '/home/phpdebug/www/' => '/projectroot/'
        ),
    'HTML_DIV_images_path' => 'images', 
    'HTML_DIV_css_path' => 'css',
    'HTML_DIV_js_path' => 'js',
);
 
$allowedip = array( 
    '127.0.0.1'
);
 
header('Content-type: text/html; charset=UTF-8');
 
// Include main class
require_once 'PHP/Debug.php';
 
// Additional ini path for PEAR
define('ADD_PEAR_ROOT', '/home/phpdebug/www/libs/PEAR');
set_include_path(ADD_PEAR_ROOT . PATH_SEPARATOR. get_include_path());
 
echo '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>Pear::PHP_Debug</title>
    <script type="text/javascript" src="'. $options['HTML_DIV_js_path'] .'/html_div.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="'. $options['HTML_DIV_css_path'] .'/html_div.css" />
  </head>
<body>    
';
?>
<h1>PEAR::PHP_Debug  -------------------------></h1>
 
<p>
    <a href="PHP_Debug_HTML_Div_test.php">&raquo; HTML_DIV Renderer</a><br/>
    <a href="PHP_Debug_HTML_Table_test.php">&raquo; HTML_Table Renderer</a><br/>
    <a href="PHP_Debug_test.php">&raquo; Test min</a><br/>
    <a href="PHP_Debug_Sources.php">&raquo; Show sources</a><br/>
    <a href="http://www.php-debug.com">&raquo; Back to PHP_Debug home</a><br/>
</p>
 
<?php
// Tests variables  ============================================================
 
// One variable that will be watched by PHP_Debug
$watchedVariable = 1; 
 
// One session variable to test the debugtype = PHP_DebuLine::TYPE_ENV (4)
$_SESSION['Kikoo'] = "One session variable defined";
 
 
 
// Debug Object creation =======================================================
 
$Dbg = new PHP_Debug($options);
 
 
// Test restrictAccess() function, only IP in param array will see the debug ===
//$Dbg->restrictAccess($allowedip);
 
 
// Test add() function =========================================================
 
// Standard
$renderer = 'HTML_Div';
$intro = 'This is the <b>'. $renderer.'_Renderer</b>, client IP is '. 
    $_SERVER['REMOTE_ADDR'];
$Dbg->add($intro);
 
// Standard, fix end and start time manually
$debug_line = $Dbg->add('Manual performance monitoring');
$debug_line->setStartTime();
for ($i = 0; $i < 20000; $i++) {
    $j = 0;
}
$debug_line->setEndTime();
 
// Application settings ========================================================
 
// Add an application setting
$Dbg->addSetting($renderer, 'app_renderer_mode');
 
// Add a group of application settings
$Dbg->addSettings($options, 'app_settings');
 
 
// Test dump() function ========================================================
 
// dump a variable (integer)
$foo = 555;
$Dbg->dump($foo, 'Foo');
 
// dump a variable (double)
$foo2 = 37.2;
$Dbg->dump($foo2, 'Foo2');
 
 
// dump an array
$Dbg->dump($options, 'Options');
 
 
// dump an object
$testObject = new PHP_DebugLine('info info info inside DebugLine object');
$testObject = $Dbg->dump($testObject);
 
// test the automatic return of debug line objects by the public functions 
//$testObject = $Dbg->dump('i am the object');
//PHP_Debug::dumpVar($testObject, '$testObject', 1);
 
// dump an object and die the script 
//PHP_Debug::dumpVar($testObject, 'stooooooop', true);
 
 
// Test setAction() ============================================================
 
 
// Type 12 : Page action : --> Methode publique a creer
$action = 'view_test_action';
$Dbg->setAction($action);
 
// Test watch() function, watched var is 'watchedVariable' =====================
 
// /!\ Be carefull the tick directive does not work under windows /!\
// and make apache crash. To test under unix, remove comments bellow and
// corresponding brace line 195 
  
//declare (ticks = 1) 
//{
 
    // Watch the variable called 'watchedVariable'
    //$Dbg->watch('watchedVariable');
 
 
    // Stress backtrace function (check line, file, function, class results) ===
 
    function a()
    {
        global $Dbg, $watchedVariable;
        $Dbg->addDebug('call from a() fonction');
        $Dbg->stopTimer();
    
        $watchedVariable = 501;
        
        b();
    }
    
    function b()
    {
        global $Dbg, $watchedVariable;
        $Dbg->add('call from b() fonction');
    
        $watchedVariable = 502;
    }
 
    a();
    
    $Dbg->addDebugFirst('call after b() and a() but adding in 1st');
    
    $watchedVariable = 555;
    $watchedVariable = 'converting from INT to STR';
 
//} // End of declare {ticks=n}  block
 
 
// Test the add() function with the timer ======================================
 
$debug_line2 = $Dbg->add('PERF TEST : 10000 iteration');
 
$y = 0;
for ($index = 0; $index < 10000; $index++) {
    $y = $y + $index;
}
$Dbg->stopTimer();
$Dbg->dump($debug_line2);
 
 
// Test the database functions =================================================
 
// Database related info
$Dbg->queryRel('Connecting to DATABASE [<b>phpdebug</b>] dns: root:user@mysql');
$Dbg->stopTimer();
 
// Query
$Dbg->query('SELECT * FROM PHP_DEBUG_USERS');
 
$y = 0;
for ($index = 0; $index < 10000; $index++) {
    $y = $y + $index;
}
$Dbg->stopTimer();
 
 
 
// Test custom error handler ===================================================
 
echo $notset;                      // Will raise a PHP notice
fopen('not existing!', 'r');       // Will raise a PHP warning
trigger_error('This is a custom application error !!', E_USER_ERROR);
                                   // Will raise a custom user error
$Dbg->error('Bad status of var x in application PHP_Debug');
                                   // Will add an application error
 
// Display Debug information (HTML_Table renderer) =============================
 
$Dbg->display();
 
// Test __toString(), dumpVar() functions and structure of Debug object ========
 
//echo $Dbg;
 
// END =========================================================================
?>
 
</body>
</html>
23-06-2017 03:34:14
» Design taken and adaptated from PHP::Pear website
» Show source of this file
» Click here to register the newsletter
Last updated: 21 June 2011 by COil
Close