PHP Tutorial

 

Table of Contents

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. Before you begin, ensure that line numbering is enabled in Komodo (View|View Line Numbers).

  1. 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.
  2. 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.


  1. 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.
  2. Line 9: Step In Select Debug|Step In. "Step In" 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.
  3. View Variables Expand the Output Pane (if necessary) by clicking and dragging the bottom margin of the Komodo workspace. Click the Debug Variables tab. Both pre-defined PHP variables and variables defined in the program are displayed on the Locals tab.
  4. View Output Click the Debug Output tab. Notice that the HTML tags from lines 1 to 8 have been written to the Output Pane.
  5. Line 19: Step In The debugger moves to line 149, bypassing the entire GuestBook class. The GuestBook class will be called from line 149.
  6. Line 149: Step In The debugger is now processing the GuestBook function.
  7. View Variables Only variables declared in the scope of the GuestBook function are displayed. The Globals tab displays all variables.
  8. Line 32: Step In The "global" statement adds the variable $HTTP_SERVER_VARS to the scope of the GuestBook function. It is now displayed on the Locals tab (on the Debug Variables tab).
  9. Line 33: Step In 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.
  10. Line 34: Step In The debugger will proceed to the _getData function. Continue to select Step In to process each statement in the function. After line 52 has been processed and the debugger is stopped at line 53, the $lines variable can be expanded to view the contents of $this->gb_dat (guestbook.dat).
  11. Line 53: 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.
  1. Line 38: Step In Continue to select Step In until the debugger is on line 121, in the addGuestBookEntry function. On line 121, the addGuestBookEntry function calls the _createEntryHTML function .
  2. Line 121: Step In In the _createEntryHTML function, the program assigns variables to the CGI input data configured in the Debugging Options.
  3. Line 71: Step Out The _createEntryHTML function will complete, and processing will return to line 122.
  4. Line 122: Step In Use Step In to process each line of the addGuestBookEntry function, until processing moves to the _writeDataFile function on line 102.
  5. Line 102: Step In Process line 102.
  6. 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.
  7. Line 103: Step In Continue to select Step In until line 108 has been processed. After line 108 is processed, the contents of the $this->data variable are written to the datafile, as displayed in the Watch window.
  8. Line 111: Step Out Processing returns to line 43 of the GuestBook function
  9. Line 43: 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.
  10. Line 44: Step Over The debugger will execute the outputForm function, which writes the HTML form to the Output Pane.
  11. Continue Select Debug|Continue to run the debugger to the end of the program.

Top Previous Next