Skip to main content

Debugging PHP using Eclipse and PDT

Use XDebug or Zend Debugger to boost your productivity when fixing bugs in PHP applications

Nathan A. Good, Senior Information Engineer, Freelance Developer
Nathan Good lives in the Twin Cities area of Minnesota. Professionally, he does software development, software architecture, and systems administration. When he's not writing software, he enjoys building PCs and servers, reading about and working with new technologies, and trying to get his friends to make the move to open source software. He's written and co-written many books and articles, including Professional Red Hat Enterprise Linux 3, Regular Expression Recipes: A Problem-Solution Approach, and Foundations of PEAR: Rapid PHP Development.

Summary:  The PHP Development Tools (PDT) plug-in, when installed with Eclipse Europa, gives you that ability to quickly write and debug PHP scripts and pages. PDT supports two debugging tools: XDebug and the Zend Debugger. Learn how to configure PDT for debugging PHP scripts and discover which perspectives you use when taking closer looks at your scripts.

Date:  17 Jun 2008
Level:  Intermediate PDF:  A4 and Letter (823 KB | 35 pages)Get Adobe® Reader®

Comments:  

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 PHP Debug perspective

The Debug view

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

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 Variables view


The Breakpoints 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
The Breakpoints view


The Editor 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
The Editor view


The Console 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

The Debug Output view displays the output from the debugger, where applicable. The Zend Debugger displays information in this view.

The Browser Output 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.

3 of 11 | Previous | Next

Comments



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=313756
TutorialTitle=Debugging PHP using Eclipse and PDT
publish-date=06172008
author1-email=mail@nathanagood.com
author1-email-cc=cappel@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).