note 94702 added to debugger
| From: | frankatsilverwolfmediadotherecom at osu1 dot php dot net | Date: | Thu, 19 Nov 2009 12:23:42 +0000 |
| Subject: | note 94702 added to debugger | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163072@lists.php.net to get a copy of this message | ||
I always include debugging code in all may major projects. I use an object (e.g. $CFG) to store the
settings the control the code's behavior, which includes a $CFG->debug variable to control
the level of debugging verbosity. I set it to 0 before rollout, which ensures that even if some
debugging code was left in accidentally, this will be deactivated and not spew debugging information
in a live website.
I use the following functions to facilitate debugging messages. They live in a single code module
which I only need include() to use it. Note the global reference to $CFG:
// Dump the contents of a variable into HTML comments for debugging:
function debugVar ($var) {
global $CFG;
if ($CFG->debug) {
echo "\n<!--\nDEBUG INFO: \n";
if (is_array ($var))
print_r ($var)
else
var_dump ($var);
echo "\n-->\n";
}
}
// Dump function parameters into HTML comments for debugging:
function debugFunc () {
global $CFG;
if ($CFG->debug) {
$argv = func_get_args ();
echo "\n<!--\nDEBUG INFO: \n";
print_r ($argv);
echo "\n-->\n";
}
}
// Dump a debugging message into HTML comments for debugging:
function debugMsg ($msg) {
global $CFG;
if ($CFG->debug) {
echo "\n<!--\nDEBUG INFO: \n";
echo $msg;
echo "\n-->\n";
}
}
Usage is simple:
To check a variable, call debugVar ($variable);
To check parameters passed to a function, call debugFunc ($var1, $var2, $var3 ...);
To print a debug message, call debugMsg ("Function xyz returned " . $retVal);
Then check your HTML source to find the debugging output in the comments.
Don't forget to set $CFG->debug to 0 before rollout. If you're paranoid you can also
include a javascript alert() box to be triggered by a : $CFG->debug > 0" condition upon
each page reload, although that gets really annoying really fast. :-)
// Frank
----
Server IP: 69.147.83.197
Probable Submitter: 196.25.255.214
----
Manual Page -- http://www.php.net/manual/en/debugger.php
Edit -- https://master.php.net/note/edit/94702
Del: integrated -- https://master.php.net/note/delete/94702/integrated
Del: useless -- https://master.php.net/note/delete/94702/useless
Del: bad code -- https://master.php.net/note/delete/94702/bad+code
Del: spam -- https://master.php.net/note/delete/94702/spam
Del: non-english -- https://master.php.net/note/delete/94702/non-english
Del: in docs -- https://master.php.net/note/delete/94702/in+docs
Del: other reasons-- https://master.php.net/note/delete/94702
Reject -- https://master.php.net/note/reject/94702
Search -- https://master.php.net/manage/user-notes.php