views:

49

answers:

1
+1  Q: 

debugging tools

I am using Netbeans and programming with PHP. I have seen debugging tools like watches and call stacks. What exactly are watches and call stacks? How do I use them in Netbeans?

+1  A: 

Watches allow you to mark a variable or code point for more inspection throughout the execution of the script. For example:

$x = 0; // If we were watching x here, we'd see the value as 1 after the next line executes.
$x++;

Call stacks show the trace of the current function or method which is being executed. These are often only shown when an error is encounted, but can be shown when watching/breaking on a variable or function. For example:

class foo {
    public static function bar() {
        echo_fail('bar');
    }
}
foo::bar(); // This will show a call stack of Class foo -> function bar, or something similar, because the function echo_fail does not exist. It often shows memory usage and time for execution, too!

To use both, simply enable the debugging features of Netbeans by following the instructions here: http://tekyzone.blogspot.com/2008/07/setup-netbeans-php-debug-environment.html. You can also find plenty of information at the Xdebug website: http://www.xdebug.org/

Nathan Kleyn