DebugPanel - Web 2.0 way of print_r()
Target Audience
Novice and intermediate PHP developers who are debugging the code by inserting
print_r($var); // or var_dump($var); // or var_export($var);
Note: those who are using DBG, Xdebug, Zend Debugger or others, please ignore this "lame" script - it will only make you laugh.
Purpose
Most of PHP developers start debugging by inserting something like this in their code and seeing results on the screen.
$var = call_some_obscure_function(); print '<pre>'.print_r($var, true).'</pre>';
DebugPanel also outputs the variable contents on the screen, but not directly at the place where it's called, but in a window floating over your script output with many convenience features.
Feature list
- Collect all variable dumps in one place.
- Highlight the syntax a little (different variable types get different background).
- Save screen space by toggling visibility of different variables.
- Handle multidimentional arrays with ease.
- DebugPanel is displayed with
position: absolute
which is not interfering with the output of your script. - Drag and drop DebugPanel so it will not cover important information on your screen.
- Never get warnings that you are trying to send HTTP headers or set cookies AFTER outputting debug information.
- Handle objects as easy as multidimentional arrays.
- Use the included PHP profiler to find the slowest code block in your script.
- Use the included server statistics module to know what's going on with your server.
- Remembers it's position after dragging, giving you pleasant debugging time!
Demo
If you haven't noticed - here it is, on the right of this page. Drag it and inspect it. Click on array titles to toggle visibility.
Usage
Step 1
Include the PHP class into your initialization (bootstraping) script.
require_once('class.DebugPanel.php');
It will automatically attach itself to the end of your script by using
register_shutdown_function()
and so render the DebugPanel in the browser.
Step 2
Call
dp('return value from strange function', $var);
every time you want to debug something.
Download
DebugPanel.zipSomebody wants to host the file for me?
Todo
I don't have any plans yet. Please try DebugPanel and report bugs and suggestions.
Hint about Taylor Profiler
That's the way I use Taylor Profiler in my code (which takes care of the current class name and current function name in one go):
function some_slow_function() { if (isset($GLOBALS['profiler'])) $GLOBALS['profiler']->startTimer(__METHOD__); sleep(1); if (isset($GLOBALS['profiler'])) $GLOBALS['profiler']->stopTimer(__METHOD__); }
DebugPanel
Request (array[7])
key | typeName | value |
---|---|---|
v1st | string(16) | 8485AB8ACB4BBF90 |
MANTIS_VIEW_ALL_COOKIE | string(2) | 50 |
_csoot | string(13) | 1268814504774 |
_csuid | string(16) | 48b417b23862dc80 |
MANTIS_STRING_COOKIE | string(64) | 8bac76e935a27df7c99e72a7536cbfaae589e74d8380b7c59f407a5626c4508d |
MANTIS_PROJECT_COOKIE | string(1) | 6 |
livecid | string(32) | WI0om32G7446uxjqY4Kzg3Rs5LhQ8Fr2 |
System Variables (array[7])
key | typeName | value | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
REQUEST | array[7] | REQUEST (array[7])
| ||||||||||||||||||||||||
GET | array[0] | |||||||||||||||||||||||||
POST | array[0] | |||||||||||||||||||||||||
FILES | array[0] | |||||||||||||||||||||||||
COOKIE | array[7] | COOKIE (array[7])
| ||||||||||||||||||||||||
SESSION | NULL | |||||||||||||||||||||||||
GLOBALS | NULL |
Test (array[8])
key | typeName | value | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
string | string(12) | Hello World! | ||||||||||||||||||
int | integer(2) | 10 | ||||||||||||||||||
double | double(6) | 3.1428 | ||||||||||||||||||
null | NULL | |||||||||||||||||||
bool | boolean(1) | 1 | ||||||||||||||||||
array | array[5] | array (array[5])
| ||||||||||||||||||
panel | array[1] | panel (array[1])
| ||||||||||||||||||
someHTML | htmlString | someHTML (htmlString)HiI am an HTML string. |
TaylorProfiler (htmlString)
nr | count | time, ms | percent | routine |
---|---|---|---|---|
1 | 1x | 1000.20 | 99.78% | some_slow_function |
2 | 0x | 0.00 | 0.22% | Missed |
3 | 1x | 0.03 | 0.00% | unprofiled |
1002.40 | 100.22% | OVERALL TIME |
No comments:
Post a Comment