PHP, Eclipse and the Zend Framework

So I jumped at the idea of working on a PHP/Zend project.  I mean, who doesn’t relish the thought of developing in a weakly-typed language that seems more like a virtual explosion of the key-word and function factory than an actual language alongside a bloated, overly complex MVC framework?  Throwing caution to the wind, I dove in head-first without so much as checking the temperature of the water … or if there even was water to begin with.

First things first, I would need an IDE.  The previous developer had established the project using Komodo 7, an IDE that’s dedicated to PHP development and works well with the Zend Framework, which was the MVC library this existing project was built upon.  Installing and configuring Komodo was relatively painless; the trial version provided a full-featured IDE that wasn’t hobbled in any way.  Wait a minute – I said “trial” didn’t I?  With a trial period of only 21 days, if you plan to be developing for more than 3 weeks, you’ll soon reach the end of that road where the barriers are adorned with $300 price tags.  I’m sure most would agree that this is always a nice thing to be presented with in the open-source world…or not.
With my trial period expired and tears in my eyes, I set my sights set on something more traditionally open-source:  The 900lb gorilla of the Java world – Eclipse.  Some research yielded the presence of a plugin known as the “PDT” – “PHP Development Tools.”  Using Eclipse’s “Install New Software” feature was easy to pull down the PDT and get it setup and working.  With the PDT installed, I setup my project workspace and checked my project out from the svn repository.
The PDT added a new “PHP” perspective to my Eclipse IDE, which worked quite well for editing my PHP source.  Now, to be fully functional, I only had a few tasks left to tackle:

Add a reference to the Zend Framework to the project’s Include Path
Install some DBGp-compliant debugger

Adding the Zend Framework to the include path was a two-step process.  For the first step, I had to add the Zend Framework library as a general “PHP Library.”  To accomplish this in the IDE, I navigated to Window -> Preferences, expanded the “PHP” section and selected “PHP Libraries.”  Clicking the “New” button allowed me to create a friendly name and placeholder for the library.  I named my library “ZendFramework v1.11” and clicked “Ok.”  Next, I clicked on my newly-created library item, and clicked the “Add External Folder” button.  This allowed me to browse to the folder where I had the Zend Framework installed (in my case, /usr/lib/ZendFramework/library).  Now that I had included the Zend Framework into the IDE as an available PHP library, I just needed to add a reference to it in my project’s include path.  In the IDE menu, choose Project -> Properties.  In the Properties dialog for the project, click on the “PHP Include Path” option on the left, and then select the “Libraries” tab on the right.  Click “Add Library” followed by the next button on the resulting dialog box.  Check the Zend Framework library, and click Ok and Ok.  Voila – your project now includes the Zend Framework.
The last step was to set up a debugger.  XDebug was already on the system and seemed to be the logical answer.  Opening the php.ini file in the /etc directory showed configuration for XDebug that all I needed to do was uncomment, and provide a path to the PHP Zend-friendly xdebug extension (which I found in /usr/lib64/php/modules/xdebug.so).  The final step was to tell Eclipse to use XDebug.  You can find the debugger configuration information under Window -> Preferences -> PHP -> Debug.  Set the debugger to be XDebug.  If you’ve set the debugger to run on a port other than the default 9000 that the php.ini file specifies, you’ll need to change which port Eclipse uses by clicking the “Configure” link next to the PHP Debugger dropdown.
I added a new debug configuration under Run -> Debug Configurations -> PHP Web Application.  Again, here I specified that I would be using XDebug, and then provided a default entry-point into my project by browsing to my root index.php file, and then unchecking the “Auto Generate” checkbox under “URL”, and providing an MVC-compliance url.  Click the “Debug” button would launch my web app at the indicated URL, and the code would break on my established breakpoints.
So now I’ve been happily coding along in PHP with Eclipse.  Every day it reminds me of why I like Visual Studio and the .NET Framework so much.  Now it’s just a matter of actually getting this pushed over into QA.  Hey, who drained all the water out of the pool?

Originally Published here: http://blog.murphomatic.com/post/2012/10/22/PHP-Eclipse-and-the-Zend-Framework.aspx