Working with the Debugger

The purpose of this tutorial is to teach you how to debug files and applications both remotely and locally in order to gain maximum efficiency and accuracy from your files and projects.

Contents

Purpose and Usage

 

Debugging PHP Files (PHP Scripts)

 

Debugging PHP Applications (PHP Web Pages)

 

 

 

 

 

 

Purpose and Usage

The Zend Debugger can detect and diagnose errors in PHP code situated locally or on remote servers. The debugger allows you to control the execution of your program by setting breakpoints, suspending launched programs, stepping through your code, and examining the contents of variables.

Debugging should be used at stages where your scripts and applications are formed sufficiently to be tried and tested.

The Zend Debugger has two main features:

Back to Top

Debugging PHP Files (PHP Scripts)

Files on your workspace can be debugged locally using PDT's internal debugger.

 

 

Instructions on how to complete a procedure

This procedure demonstrates how to debug a file locally:

  1. Create a PHP file, called "debug", and copy-paste the example code into it. (Click here to see the code.)

  2. Set a breakpoint at line 103 by double-clicking the marker bar to the left of the editor window.
    A blue ball will appear.

  3. Save the file.

  4. Click the arrow next to the debug button on the toolbar and select Open Debug dialog –or- select Run | Open Debug dialog from the main menu.
    A Debug dialog will appear.

  5. Double-click the PHP Script option to create a new debug configuration.

 

  1. Enter a name for the new configuration.

  2. From the PHP Debugger drop-down list, select whether to use the Zend Debugger or XDebug.

  3. Select the required PHP executable. This must match the PHP executable used for the project.

  4. Under PHP File, click Browse and select the "debug" file.

  5. Ensure that the 'Break at First Line' Breakpoint checkbox is selected.

  1. Click Apply and then Debug.

  2. Click Yes if asked whether to open the PHP Debug Perspective.

  3. A number of views will open with information about your script.

  4. The Debug View is where the debugging process can be monitored and controlled.

The debugging process will currently have stopped where your first <?php label appears.

  1. Click the Resume icon to continue to the breakpoint.

  2. Click Step Into . The Debugger goes into the function defined in line 103 and advances to line 77.

  3. The Variable view will now display various information about the relevant variables and parameters through which the function was reached.

  4. In the editor window, place and hold the cursor over $worker_name, $worker_address, and $worker_phone. A tooltip appears displaying the variable values.

  1. Click Step Return. The cursor returns to line 103.
    The Debug Output view will display the HTML output created up until the breakpoint, while the Browser Output view will show the current output to a browser.

  2. In the Debug view, click Resume  until the debugging process is terminated.
    Notice that as the debugging process progresses, the Debug Output and Browser Output displays are updated.

  1. The console view will display any errors or warnings about your script. In this case, it will display a Notice about an undefined variable on line 105.

  2. Click on the PHP Perspective icon to return to normal editing mode.

  3. To run the debugging process again, click the arrow next to the debug icon on the toolbar and select your configuration -or- select Open Debug Dialog and double-click your configuration from the Debug dialog.

 

Back to Top

Debugging PHP Applications (PHP Web Pages)

PDT also allows you to debug applications, projects or files that are already on the server. Using the debugging process, you can also create an application in PDT and publish it to the server before debugging.

Note:

Your server must be running the Zend Debugger in order for remote debugging capabilities to function.
The Zend Debugger comes bundled with Zend Core and Zend Platform, but can also be downloaded as a separate component from http://downloads.zend.com/pdt/server-debugger.

 

 

Instructions on how to complete a procedure

This procedure demonstrates how to debug applications on a server:

  1. Create a new PHP file, called "form1", with the following code:

<html>

<body>

<form action="welcome.php" method="post">

Name: <input type="text" name="name" />

Age: <input type="text" name="age" />

<input type="submit" />

</form>

</body>

</html>

  1. Create a second PHP file, called "welcome", with the following code:

<html>

<body>

Welcome <?php echo $_POST["name"]; ?>.<br />

You are <?php echo $_POST["age"]; ?> years old.

</body>

</html>

  1. Save both files.

  2. Click the arrow next to the debug button  on the toolbar and select Open Debug dialog –or- right-click the file in PHP explorer or within the file's editor window and select Debug as | Open Debug dialog.
    A Debug dialog will appear.

  3. Double-click on the PHP Web Page option to create a new debug configuration.

  4. Enter a name for the new configuration.

  5. Select the Debugger to use from the Server Debugger drop-down list.

  6. Ensure that your server is selected from the list.
    If you have not configured a server, click New and enter:

  1. Your server's name.

  2. Tthe URL of its document root.

  3. The location to which you would like to publish the files.

  4. Mark the Publish Projects to this server checkbox.

  1. As the files still do not exist on the server, you will need to publish them before they are debugged by doing the following:

  1. Ensure that the Publish Projects to this Server checkbox is marked within the Server settings, and specify the Directory to which the files should be published. (To do this, click Configure under the Server category.)

  2. Under the File/Project category, click Browse and select the "form1" file. This will be the file from which the debugger will start debugging.

  3. Mark the Publish files to Server checkbox and, if necessary, add the root folder to which you would like to publish the file in the 'Publish To' box.

  4. Ensure that the URL to which files will be published is correct.

  5. If this is not correct, unmark the Auto Generate checkbox and manually change the URL.

  1. Click Apply and then Debug.

  1. PDT will now upload the files to your server and begin the debugging process.

  2. Click Yes when asked whether to open the PHP Debug Perspective.

  3. The Debug Perspective will open with several views relevant to the debugging process (See step 17, under "Debugging a PHP File Remotely", above, for information on the different views.)

  4. In the editor view, you will see the code for the "form1" file.

  5. In the Debug view, click Resume to resume the debugging process.

  6. The browser output will display a form asking you to enter your Name and Age.

  7. Select the browser view (tabbed with the editor window). This will display the output of your script in a browser in 'real time'.
    Note that this is different from the Browser Output window.

  8. In the browser view, enter your Name and Age and click Submit Query.

  1. Another editor tab will open, with the script from the welcome.php file.

  2. In the Debug view, click Resume to resume the debugging process.

  3. The browser output and browser views will display the final result of your application:
    "Welcome [Name].
    You are [Age] years old."

  1. The debugging process will have terminated.

  2. Click on the PHP Perspective Icon to return to normal editing mode.

  3. You may now make changes to your code and debug them without having to publish to the server, by executing the following steps:

  1. Make some changes in the script of the local copies of your file.

  2. Open the debug dialog (see step 4, above).

  3. Select your last debug configuration to open its settings.

  4. Unmark the Publish Files to Server checkbox.

  5. Click Apply and Debug.

  6. The debugging process will now be applied to your local files without them being published to the server.

  1. To run the debugging process again, click the arrow next to the debug icon on the toolbar and select your debugging configuration.

 

Back to Top

 

 

Related Links

Related Links:

Debugging

Debugging a PHP Script

Debug Preferences

Debugging a PHP Web Page

Locally Debugging a PHP Script

Running and Analyzing Debugger Results

Run Menu

 

 

Back to Top