When developers are debugging their code, if they are not able to use a debug program, where execution can be followed line by line, they often resort to adding lines of code to trace the values of variables. In many cases they write the output to the web page, or to a file.
The oik-bwtrace plugin provides an easy to use API that assists in the problem determination. It writes its output to a trace file, so it does not alter what you see on the web page.
It can be dynamically enabled and disabled at runtime. The APIs are implemented as lazy APIs. They are dormant until trace is activated and enabled. Therefore, there is no real need to remove the trace (debug) statements when the code goes “live”.
During development of the oik plugins, Bobbing Wide have often resorted to using these trace functions in order to understand some of the stranger behaviour of WordPress, PHP and other plugins and themes.
bw_trace2() function
The bw_trace2() provides an easy way to see content in context.
You appear to be a bot. Output may be restricted
<br /> bw_trace2( $value=null, $text=null, $show_args=true, $trace_level=BW_TRACE_ALWAYS );<br />
The variable passed to bw_trace2() may also be an array or object. This enables the developer to quickly see all of the current content of a particular variable.
This function uses debug_backtrace() to determine the function, line and file parameters to report.
By default, bw_trace2() will print the values of the parameters to the function from which it is called to a trace file.
Assuming the value of the $store
variable was "2"
then
the output that you see in the trace log will be similar to this:
\wp-content\plugins\oik\oik-tides.php(140:0) 2011-09-12T17:02:42+00:00 bw_tides store 2
bw_backtrace() function
The bw_backtrace() function allows you to find out the call hierarchy for a function.
You can see the context in which the function was invoked; call stack and parameters.
Use this function sparingly.
You appear to be a bot. Output may be restricted
<br /> bw_backtrace();<br />
bw_gobang() – Go Bang!
Or whatever you want it to be, so long as it doesn’t exist.
We use this mythical function to get a fatal error.
if ( $this != $that ) {
bw_trace2( $this, "this" );
bw_trace2( $that, "that", false );
bw_backtrace();
gobang();
}
crash();
It’s good when you want to demonstrate that your code IS being run.
Use this function even more sparingly than bw_backtrace().