The PHP Debug perspective
Before setting up the debuggers and starting to debug the projects you've just created, familiarize yourself with the PHP Debug perspective so you feel comfortable debugging your PHP application.
The first time you choose Debug As > PHP Script or Debug As > PHP Web Page to debug a PHP file, Eclipse asks if you want to switch to the PHP Debug perspective. If you click Yes, the perspective shown in Figure 4 appears. The different views contain most commonly used information while debugging a PHP script.
Figure 4. The PHP Debug perspective
The Debug view displays information about the processes that are running. On the tab shown in Figure 5, the code is stopped at line 5. Line 5 is inside the sayHello() function, which is listed in the view. The {main} entry always refers to the main body of the script, and you can tell by looking at the information in the Debug view that sayHello() is at line 13 of the script.
Figure 5. The Debug view
The Debug view has several buttons along its top border. While debugging, you use these buttons to step through, over, or out of parts of your PHP files. The buttons most commonly used are:
- Remove all terminated launches
- This cleans up your Debug view by clearing all the terminated (completed) launches from the view. Whenever you start debugging a PHP file, a launch is recorded in the Debug view that has information about the process that was executed. After the process is terminated, it still hangs around in the Debug view. You can relaunch it by clicking Relaunch in the context menu.
- Execute to the next breakpoint
- The debugger runs the current debug process until the next breakpoint. If you have no breakpoints set, the process runs through to completion.
- Pause the debugger
- Pause the process wherever it is currently. This can be convenient when debugging long-running loops to find out where you are if a breakpoint wasn't set.
- Terminate the debugger
- Stop debugging.
- Disconnect the debugger
- If you're debugging on the server, clicking this disconnects the debugger client from the server. The server continues processing.
- Step into the code
- If the current line is a function, the debugger steps into the function so you can debug it.
- Step over the code
- If the current line is a function, the debugger skips over the function. The code inside the function will still be executed, but you won't have to step through it.
- Step out of the code
- If you're in a function and decide you don't want to debug anymore, click this. The function executes to completion, and your current stop point in the debugger jumps to the caller of this function.
The Variables view contains information about the variables that are in scope.
Variables appear or disappear from this view as they come in and out of scope. The
example below shows the values of the variables $howManyTimes
and the looping variable $i.
Figure 6. The Variables view
The Breakpoints view displays all breakpoints set for the entire project. From this view, you can temporarily disable a breakpoint by clearing the checkbox next to the breakpoint.
Figure 7. The Breakpoints view
While you are stepping through the code, you can see the code in the PHP editor in the Editor view.
Figure 8. The Editor view
If your PHP file is a simple script that prints messages using the print() or echo() method, those messages will appear in the Console view. For the simple example in this tutorial, you'll see the greeting printed to the console several times.
The Debug Output view displays the output from the debugger, where applicable. The Zend Debugger displays information in this view.
The Browser Output view shows what would be displayed to the browser if the PHP script were a Web page. When using the Zend Debugger, the output of the Web page while it is being drawn is printed here, in its raw HTML form. Seeing your page in this form may be helpful for those HTML elements that aren't necessarily visible when viewing your Web page in a browser.
