posts | commentsAdd to Google
20
Mar

Eclipse, a PHP IDE

comments1 comment so far

     “Ok, so I have a great text editor. Why do I need an IDE?”   A very common question especially among PHP developers. There are many different text editors that do a really good job when you need a basic text editor and maybe a little syntax highlighting. But what does a full fledged IDE typically offer that a text editor does not?

  • Project Management.
    •  A PHP application (or any application for that matter) is rarely a single text file. Its typically many files and a folder structure. It is very difficult to keep track of your code when it is spread out so far across a spectrum. An IDE offers features such as bookmarking, a to do list, and even keeping track of errors.
  • Re-factoring
    • I don’t know of a single programmer who hasn’t, at one time or another, needed to change the name of a file or move the file to a different location. The problem is, in PHP applications, one file is usually included in many different files, so you have to remember every place that you have included that file and change it, otherwise you will get an error. Re-factoring is an automated way of changing the file-name and all of the references to that file. For all of you incredible programmers who have never needed to change the names or locations of a included file, we, mere mortals, solute you.
  • Searching and replacing
    • Most text editors allow you to search within an opened page of a file, but a good IDE will allow you to find and replace bits of code throughout your project. This can save alot of time and effort.
  • Code completion / insight windows
    • So you write a few classes or functions and put them into a separate file and include that file in your PHP project. Great! Now all you have to do is call that function and pass it the arguments,,,, wait,, what was the name of that function again? What were the arguments I was supposed to pass? Code completion can help you remember all of the above.
  • Debugging
    • Every programmer writes buggy code. Anyone who claims otherwise is not being honest. Most good IDEs will underline syntax errors that it finds throughout your code as your writing it. Also, most IDEs have debugging features that allow you to trace, step through and otherwise profile your code.
  • Team tools
    • If you are working in a development environment with other programmers or if you are working alone, you will want to be able to undo changes that you have made to your code. This can save many hours of time and trouble and is a must for any developer. Most IDEs have plug-ins for version control software such as CVS or Subversion. As George Schlossnagle said in his book Advanced PHP Programming not utilizing version control is like ‘…walking a tightrope without a net’.

There are several IDEs for PHP. The one that has worked best for me is Eclipse PDT. Eclipse was originally designed to build Java applications, but has been adapted to many different programming languages including PHP. Since Eclipse was developed as a Java application it can run on many different desktop operating systems including Ubuntu and Windows as long as you have JRE 5 installed on your computer. For the purpose of this article Eclipse in Microsoft Windows is assumed.

Eclipse PDT has many great features and since Eclipse is an open source, plug-in based application you can download hundreds of plug-ins at http://www.eclipseplugincentral.com/.

Another nifty tool for your web development environment is a good ftp application. One that I have found works especially good with Eclipse PDT is http://www.webdrive.com/. Webdrive allows you to connect to an ftp/sftp/webdav/FrontPage/GroupDrive and use it as though its a drive on your local computer.

Last but not least is a good development environment you can debug your PHP code in. The easiest environment to setup is a project called XAMP. XAMP comes prepackaged with a debugger called XDEBUG that Eclipse can utilize to debug your code. To setup XDEBUG, simply go to your XAMP install and go to C:/xamp/apache/bin/php.ini and un-comment the XDEBUG extension (make sure that you comment out Zend Optimizer as the two don’t get along with each other).

xamp_phpini_xdebug Eclipse, a PHP IDE

You will have to restart apache before the changes are applied. To verify that XDEBUG is loaded simply add a .php file to your project and input phpinfo(). Open up a web browser and type localhost/whateverpathyourscriptislocated.php and you should see something like this:

xdebug_phpinfo Eclipse, a PHP IDE

If you don’t see the XDEBUG entry in phpinfo, make sure that php_xdebug.dll is in the folder ‘C:/xamp/php/ext’. Also, check to see where the loaded php.ini file is located.

To setup Eclipse with XDEBUG, click on the down arrow next to the debug icon and select ‘Open Debug Dialog’:

Eclipse Debug

Set the ‘Server Debugger:’ to XDEBUG, click ‘Configure’ to select the php.exe (usually in C:/xamp/PHP/php.exe). Select the php file you wish to debug by clicking browse and selecting the php file in your project.

Eclipse Debug Dialog

So now your ready to begin. Click ‘Debug’ and Eclipse will pause the code and show you variables in scope and their values.

Line Break

These features are very helpful in many situations. For instance, what if you are working on an application that you didn’t write? Eclipse will help you keep track of objects and functions with code completion, project management and good searching capabilities. You can debug and profile your code with XDEBUG and find problems with your code that aren’t necessarily errors, but just unexpected results.

Categories: PHP
Bookmark and Share

Thursday, March 20th, 2008 at 10:23 am and is filed under PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Eclipse, a PHP IDE”

  1. Posted by Herchen 20th March, 2008 at 11:20 am

    Awesome article. I have been looking for a PHP IDE now I think I will use Eclipse. I was using HomeSite for the past 8 years but my projects are getting too big and I need the refactoring and code completion. Thanks for the great instructions!

Leave a reply