Debugging
THIS has a handy, nifty, cool thing called "debugging by print statements."
We are, of course, only serious.
Debugging is turned on by setting debug
in CONFIG.INI
to be non-zero. When non-zero, diagnostic messages are displayed in one of three ways:
- Directly inline where is.
- Directly inline where is delimited by HTML comments.
- As a list upon program termination (with or without HTML comments).
Quite simple, yet quite effective.
Messages are stored (or displayed) by the function debug()
, which takes an argument of a string (or array). If no arguments are given debug()
returns the current debug setting.
A debug setting of 1 enables diagnostic messages which all get listed upon program termination. A setting of -1 turns on the immediate displaying of all debug messages. A setting of 100 is like -1 but all messages are wrapping in HTML comments. There are a few other things it can do:
debug setting result 9 appends a dump of all sitewide data 2 data dump limited to GET/POST data 3 data dump limited to constants data 4 data dump limited to GLOBALS array 200 debug messages saved to $GLOBALS['debug']
For the last case, there can be the string in the close web template:
<div id="debug">{$GLOBALS['debug']}</div>
so that they can be displayed however the CSS for the id #debug is defined.
For debugging output to be visible though, you must be logged in as Admin; this way, while you are debugging something no other visitor will see the diagnostic messages/data. The setting of 9
is an exception to this and is available only if for some reason (as has happened) there was an error logging into Admin — it can only be set in CONFIG.INI
.
The debug setting can also be controlled by debug=<value>
in the URL if you are logged in as Admin.
If CONFIGNODUMP
is defined then no data is displayed regardless of the debug setting (the Admin code does this).
Message Format
The messages displayed by debug()
have the calling file and function name prepended:
(mysqli.php,560,query) SELECT body FROM root WHERE id = 39
with the CONFIG.INI
setting of nodebugfunc
to eliminate the function name (for just a little bit more clarity), and the setting of debugmod
to show only messages from any one file:
debugmod = mysqli.php
With the setting of debugcaller
the function/location that called the function that called debug()
will be displayed:
(display.php,112)(mysqli.php,560,query) SELECT ...
All messages are filtered through htmlentities()
, and can be truncated by the optional second argument to debug()
(used when displaying post data which may be large).
As we progress with the code more features are added as we think of them. See CONFIG.INI
for other settings.
Notes
1. Resources and objects are displayed with
and get_resource_type()
.get_class()