Its been quite some time since I looked at a PHP script, the first dynamic website I built was PHP and PostgresSQL and for sometime it was PHP all the way. But sometimes project requirements dictate a certain language, so later I worked with Allaire Coldfusion, ASP and ASP.NET.
I used two debugging techniques for PHP
- The first method is turning on error reporting which is an after the fact method of determining the problem. It can sometimes be difficult to determine the cause of the problem, as error messages often tell you exactly what is wrong not the cause.
- The second method employed is printing out variables at points in my scripts to narrow down the point at where the error is occurring.
If you are new to web development and these methods and want to know more there is a good explanation on the
debugging techniques for PHP programmers using print statements, error reporting.
I thought it would be a good time to look at some of the developments in debugging PHP. Unless you write your code perfectly first time off debugging is an important part of developing any sort of software. Often a quite time consuming part.
Not new by any stretch of imagination is a third method using breakpoints to stop the execution of your code and inspect the values of variables and the flow by stepping through line by line. Using Visual Studio and ASP.NET this is easier than tying your shoe lace.
Debugging with an Integrated Development Environment and Debugger
There are number of choices available free and commercial when it comes to a PHP IDE
- NuSphere PhpED - Perhaps the leading PHP IDE, lots of features, but you will need to dust off your windows computer to run it.
- Zend Studio - Again it has plenty of features and is available for any platform I haven't tried it out yet.
- Komodo Edit and IDE - I tried the Komodo Edit on OSX seemed slightly clunky.
- Editplus - A basic text editor verging on IDE status, I quite like for typing out your code and quick edits, available for windows only.
- Eclipse PHP Development Tools - A free open source development tool that provides you with the basic code editing capabilities you need to get started. Perhaps the easiest option to get you going, Zend provide a 'all in one download' that installs Apache, PHP, MySQL and Zend Server & debugger.
I installed the Eclipse PHP Development Tools for Mac OSX and proceeded to start developing my hello world application. I've used Eclipse before for some Java projects and found it good and of course its open source and free.
- Download and extract Eclipse PDT All-in-one, I downloaded the Mac OS X (Cocoa64) version. Eclipse will run directly from the extracted folder so move it to a sensible location.
- Download and install the Zend Server Community Edition. This will install Apache, PHP, MySQL and Zend debugger.
- Configure the Apache installation , on OSX the Zend Server go to Finder > Go > Go to Folder and enter /usr/local/zend/apache2/conf from here you can edit the Apache configuration file httpd.conf.
- Open terminal and type sudo pico /usr/local/zend/apache2/conf/httpd.conf and enter your password when prompted. As long as you have permission this will allow you to edit the httpd.conf file with the required root permissions.
- I added a virtual directory /Sites to Apache to make it more accessible. To do this at the bottom of the file enter the following, of course replace with your user name.
alias /Sites "/Users//Sites"
/Sites">
Options +Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
- Open Eclipse and create a project folder in your /Users//Sites such as HelloWorld again replacing with your user name.
- Edit your project debug configuration like so, NOTE: the Zend server by default runs on the port 10088.

- Create the file index.php and enter the following to create a basic class to output "Hello World"
| < /> |
| |
| $test = new myclass(); |
| $test->hello(); |
| |
| class myclass { |
| |
| public $message = "Hello World"; |
| |
| function hello() { |
| |
| echo $this->message; |
| } |
| } |
|
| ?> |
- Add a breakpoint, in your index.php file, to do this double click in the gutter to the left of the line echo $this->message;
- Click on Run > Debug and the Eclipse perspective should change to the debug version and stop at your breakpoint.

- From here you are good to go, you can step through your code and inspect variables.
Good luck I hope this helps anyone getting started debugging PHP with Zend and Eclipse on OSX .