Debugging the Program
In this step you will add breakpoints to the program and "debug" it. Adding
breakpoints lets you run the program in chunks, making it possible to watch variables
and view output as it is generated.
- Set a breakpoint On the "guestbook.php" tab, click on the grey
margin immediately to the left of the code in line 9 of the program. This will set a breakpoint, indicated by a
green circle.
- Run the debugger Select Debug|Start
(or <F5>, or use the Debug Toolbar). In the
Debugging Options dialog box,
click OK to accept the defaults (assuming that you created the CGI variables in the
previous step).
Komodo Tip notice that the
Debugger
Options have been saved from the last time a PHP program was run or
debugged. |
Komodo Tip debugger commands can be accessed
from the Debug menu, by shortcut keys, or from the Debug Toolbar. For a summary of debugger
commands, see Debugger
Command List. |
- Watch the debug process Notice that the breakpoint
turns red, which indicates that the debugger is running. A yellow arrow on
the breakpoint indicates the position at which the debugger has halted.
- Step Into Select Debug|Step Into.
"Step Into" is a debugger command that causes the debugger to execute the
current line and then stop at the next processing line (line 19).
The lines between line 9 and line 19 are comments, not processing statements,
and are therefore ignored by the debugger.
- View Variables Expand the Output pane (if necessary)
by clicking and dragging the bottom margin of the Komodo workspace.
Click the Variables tab. Both pre-defined PHP variables and
variables defined in the program are displayed on the Locals tab.
- View Output Click the Output tab. Notice that the HTML
tags from lines 1 to 8 have been written to the Output pane.
- Step Into The debugger moves to line 149, bypassing
the entire GuestBook class. The GuestBook class will be called from line
149.
- Step Into again The debugger is now processing the
GuestBook function.
- View Variables Only variables declared in
the scope of the GuestBook function are displayed. The Globals tab
displays all variables.
- Step Into The "global" statement adds the variable
$HTTP_SERVER_VARS to the scope of the GuestBook function. It is now displayed
on the Locals tab of the Output pane.
- Step Into Expand the $this variable on the Locals
tab of the Output pane. Notice that it now has a sub-variable gb_dat, which
stores the value of the data file.
- Step Into The debugger will proceed to the
_getData function. Use Step Into to process each statement in the function.
After line 52 has been processed, the $lines variable can be expanded to
view the contents of $this->gb_dat (guestbook.dat).
- Step Out On line 53, select Step Out to process the
rest of the _getData function. The debugger will proceed to line 38,
which follows the line where _getData was called.
Komodo Tip What do the debugger commands
do?
- Step In executes the current line of code and pauses at the following line.
- Step Over executes the current line of code. If the line of code calls a
function or method, the function or method is executed in the background and the debugger
pauses at the line that follows the original line.
- Step Out when the debugger is within a function or method, Step Out will execute
the code without stepping through the code line by line. The debugger will stop on the line of
code following the function or method call in the calling program.
|
- Step Into Select Step Into until the debugger is
on line 121, in the addGuestBookEntry function. On line 121, the
addGuestBookEntry function calls the _createEntryHTML function .
- Step Into In the _createEntryHTML function, the
program assigns variables to the CGI input data configured in the
Debugging
Options.
- Step Out The _createEntryHTML function
will complete, and processing will return to line 122.
- Step Into Use Step Into to process each line
of the addGuestBookEntry function, until processing moves to the
_writeDataFile function on line 102.
- Step Into Process line 102.
- Open Watch window On line 102, the program opened the
datafile (by default, \temp\guestbook.dat). To watch the activity in the datafile,
select Tools|Watch File, then specify the datafile.
- Step Into When line 108 is processed, the contents of
the $this->data variable are written to the datafile, as displayed in the
Watch window.
- Step Out Processing returns to line 43 of the
GuestBook function
- Step Over The Step Over debugger command executes
the current line, including any functions called by the current line. When
the debugger returns to line 44, notice that the contents of the
$this->data variable have been written to the Output pane.
- Step Over The debugger will execute the
outputForm function, which writes the HTML form to the Output pane.
- Continue Select Debug|Continue
to run the debugger to the end of the program.
|