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
Studio's
Debugging feature 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.
Studio
includes several types of debugging:
Locally Debugging PHP Scripts - Debugging PHP files
using Studio's
internal PHP Executable debugger.
Remotely Debugging
PHP Scripts - Debugging PHP files using your server's debugger.
Debugging PHP Web Pages - Debugging files, applications
and projects on your server,
using the local or server copies of your files.
Debugging
URLs - Debug applications on your server by entering a URL.
Toolbar
Debugging - Debug files and applications directly from your browser
using the Zend Studio Toolbar.
Back to Top
Debugging Local PHP Files (PHP Scripts)
PHP files (PHP Scripts)
on your workspace can be debugged using
either Studios
internal debugger or your server's debugger.
Using your server's debugger, you can test the execution of the file on
your server's environment. This is especially relevant if your server's
loaded extensions are different to Studio's internal server.
|
|
|
|

|
This procedure demonstrates how to debug
a file using the internal debugger or your server's debugger:
Create
a PHP file, called "debug", and copy-paste the example code
into it. (Click here to see the code.)
Set a breakpoint at line
103 by double-clicking the marker bar to the left of the editor window.
A blue ball will appear.
Save the file.
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 -or- right-click the file in
PHP Explorer view and select Open Debug dialog.
A Debug dialog will appear.
Double-click the PHP Script
option to create a new debug configuration.

Enter a name for the new
configuration.
To debug the file using Studio's PHP Executable debugger, select the PHP Executable option
in the Debugger Location category.
-Or- To debug the file using your server's Debugger, select the PHP
Web Server option under the Debugger Location category and select your
server from the drop-down list.
If you have not configured a server, click the PHP Servers link to
be taken to the PHP Servers Preferences
page.
Under PHP File, click Browse
and select the "debug" file.
Ensure that the 'Break at
First Line' Breakpoint checkbox is selected.
Click Apply and then Debug.
Click Yes if asked whether
to open the PHP Debug Perspective.
A number of views will open
with information about your script.
The Debug View is where
the debug stack trace is displayed and the debugging process can be monitored
and controlled.

The debugging process will currently have
stopped where your first <?php label appears.
Click the Resume icon
to continue to the breakpoint.
Click Step Into .
The Debugger goes into the function defined in line 103 and advances to
line 77.
The Variable view will now
display various information about the relevant variables and parameters
through which the function was reached.
In the editor window, place
and hold the cursor over $worker_name, $worker_address, and $worker_phone.
A tooltip appears displaying the variable values.

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

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.
Click on the PHP Perspective
icon to return to normal editing mode.
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.
Clicking the debug icon will debug the last executed launch configuration.
|
|
|
Back to Top
Debugging
a PHP File Remotely
Files can also be debugged remotely
using the Debugger situated on your server. Use this function if you want
to test the execution of the file on your production environment. This
is especially relevant if your server's loaded extensions are different
to Studio's
internal server.
|
|
|
|

|
This
procedure demonstrates how to debug a file remotely:
(If you have already created the file following steps
1 - 3 under "Debugging a PHP File Locally", above, skip
to step 4.)
Create a PHP file, called
"debug", and copy-paste the example code into it
(click
here to see the code).
Set a breakpoint at line
103 by double-clicking the marker bar to the left of the editor window.
A blue ball will appear.
Save the file.
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 Debugb Dialog.
A Debug dialog will appear.
Double-click the PHP Script
option to create a new debug configuration.
Enter a name for the new
configuration.
In your new configuration
window, select PHP Web Server under the Debugger Location category.
Click PHP Servers to add
your server.
If you already have a server configured, skip to step 12.
In the PHP Servers dialog,
click New.
Enter the server's name
and its document root URL.
Click Finish and OK to add
your server and return to the debugging dialog.
Select your server from
the drop-down list.
Under PHP File, click Browse
and select the "debug" file.
Mark both checkboxes under
the Breakpoint category.
Click Apply and Debug.
The Debug Perspective will open.
In the Debug view, click
Resume until the debugging process is terminated.
The
output in the views will provide the following information:
Debug View – Here you can control (stop, pause,
and resume) the debugging process. You can also decide whether to step
into, step over or step return (step out off) certain functions.

Variables – Will display the various variables
in your script.
Breakpoints – Will display the breakpoints
you have entered
Parameter Stack – Will display the parameters
through which functions are reached.
Editor Window – will display the code at the
relevant sections, according to which line is selected in the Debug View
window.
Debug Output – Will show the textual output
of the script. This will be updated as the debugging process continues.
Browser output - Will show the output of the
script to a browser. This will be updated as the debugging process continues.

Console View – Will display any error and warning
messages.
Tasks – If you had added any tasks to your
script, these would be displayed here.
Click on the PHP Perspective
icon to return to normal editing mode.
To run the debugging process
again, click the arrow next to the debug icon on the toolbar and select your configuration
-or- select Debug and double-click your configuration from the Debug dialog.
|
|
|
Back to Top
Debugging PHP Applications (PHP
Web Pages)
Studio also allows you to debug
applications, projects or files that are already on the server. You can debug either the local (Workspace)
copy of files or the server copy of files
|
|
|
|

|
This procedure demonstrates how to debug
applications on a server:
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>
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>
Save both files and copy
them to your server.
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.
Double-click on the PHP
Web Page option to create a new debug configuration.
Enter a name for the new
configuration.
Select the Zend
Debugger from the Server Debugger drop-down list.
Select your server from
the drop-down list.
If you have not configured a server, click the PHP Servers link to
be taken to the PHP Servers Preferences
page.
Under the File/Project category,
click Browse and select the "form1" file. This will be the file
from which the debugger will start debugging (the 'debug target'.)
Ensure that the URL pointing
to the file location is correct.
If this is not correct, unmark the Auto Generate checkbox and manually
change the URL.
Note:
You can choose whether the file content will be taken from the
local copies of the files or from the files located on your server. To
select the file's Source Location, select the 'Advanced' tab and select
the relevant option under the 'Source Location' category.

Click Apply and then Debug.
Click Yes when asked whether
to open the PHP Debug Perspective.
The Debug Perspective will
open with several views relevant to the debugging process (See 'PHP
Debug Perspective' for more information on the different views.)
In the editor view, you
will see the code for the "form1" file.
In the Debug view, click
Resume to resume the debugging process.
The browser output will
display a form asking you to enter your Name and Age.
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.
In the browser view, enter
your Name and Age and click Submit Query.

Another editor tab will
open, with the script from the welcome.php file.
In the Debug view, click
Resume to resume the debugging process.
The browser output and browser
views will display the final result of your application:
"Welcome [Name].
You are [Age] years old."

The debugging process will
have terminated.
Click on the PHP Perspective
icon to return to normal editing mode.
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
Back to Top