Writing an ongoing series of articles on PHP gives you a lot of insight into the world of PHP developers. I’ve talked with many PHP programmers, and one thing that surprises me most is how few use IDEs. Most use text editors, such as Notepad on Microsoft® Windows®, Emacs, or Vim.
The text editors I mentioned (and others I didn’t) are great — I don’t want to start a pointless war over which editor is better. However, no text editor really gives you much insight into your PHP code. In particular, none views a PHP project as more than a directory of files. Let me take you into the world of IDEs, show what you can — or should — expect from them, and provide seven examples from the most popular IDE options.
In short, an IDE provides a one-stop shop for your coding work. An IDE contains an editor in which you can edit the code, debug the code, view your code in a browser (often embedded), and check in and out of source code control. To support that functionality, an IDE has a set of features you don’t find in a basic editor, such as Notepad or Vim. Again, you can extend editors to do a lot of these things, but IDEs have all this functionality in one tidy package — typically preconfigured:
- A key distinguishing feature of an IDE is that it looks at a PHP application as a project, not just a set of files. That containing concept — the project — maintains extra information, such as the configuration of the source code control, the database settings for debugging purposes, and the location of certain key directories.
- Another handy feature is integrated debugging. With this functionality, you can set breakpoints in the editor at which the PHP interpreter stops during execution of the script. From there, you can inspect the values of local variables to diagnose issues in the code. It’s a healthy alternative to sprinkling
echostatements through your code to check values or using the error log to get the values of variables.
- Code intelligence
- PHP is a very regular programming language, which means that it follows simple patterns. Not only do these patterns make it easy to write, they make it easy for an IDE to inspect the code in your project. In addition, they help you while writing by displaying the results of their inspection. For example, if you define a class with the name
MyClassin your project, the IDE then provides a pop-up window that includes
MyClassas an option as soon as you type the keyword
new. As you use the object of that type, the IDE shows its available methods and instance variables. When you start typing a function call, the IDE helps you by displaying the available arguments. Honestly, this is the No. 1 reason you should use an IDE and not a text editor. This type of code intelligence can save you hours of mistyped class names, method names, and wrong arguments.
- Class view
- A side effect of having a code intelligence engine in the IDE is that the IDE can produce a class view of the project. Instead of showing the files, the system can show you the different classes you have defined, regardless of the file they’re in. As you click the classes, your editor is taken to that file and the selection placed on the class, method, or instance variable. It’s a much nicer way of navigating around big projects.
- Support for multiple languages
- Source code control
- All the IDEs evaluated here support some connection to a source code control system, which allows you to maintain versions of the files in your project over time. You can mark particular versions of the files as a release, then revert to them when you want to roll out changes you’ve made. It’s critical in team environments to use a source code control system, but it’s important for individuals to use one, as well. A good source code control system can save you when a disk blows up or when the customer suddenly wants the version before last, rather than what you have today. Most of the IDEs support Concurrent Version System (CVS) and Subversion, which are open source control systems. One IDE supports Perforce, a commercial source code control system.
- FTP/SFTP integration
- Related to source code control is the ability to use FTP for the most recent code to the server. This is a lot easier than using an FTP client or packing up the files yourself, sending them to the server, and unpacking them.
- Database navigation
- A helpful but not essential feature is database navigation. With this feature, you can browse the database your application talks to, find out the table and field names, and run queries. Some systems even automate writing some of the database access code for you.
- Integrated Web browser
- Some of the IDEs support an integrated Web browser that can navigate directly to the page you’re editing with additional arguments you specify, the browser being hosted within the IDE or invoked externally. To be honest, I’m not a huge fan of the integrated browser because I don’t mind switching between editing the code and viewing the result in two separate applications. But I can see the attraction, and it’s not required that you use it.
- The last feature I found in all these IDEs was support for both canned and custom code snippets. Snippets are little fragments of code that perform small tasks, such as running a regular expression on some input, connecting to the database, and querying the database.
That sums up the core features you can expect from a purchased or open source IDE today. From here, we look at some popular IDEs. We’ll show some pictures of what they look like; and explain what they support, and how much they cost, if anything.
Two plug-ins support PHP in the Eclipse development platform. The first, PHP IDE Project, is an Eclipse Foundation project, which means it is released under the Eclipse license and is developed using the Eclipse Foundation’s tools and processes.
The other is PHPEclipse and is developed independently. As with Eclipse, both run on the Big Three operating systems: Windows, Linux®, and Mac OS X. You can download just the plug-ins (if you already use Eclipse), or download a pre-fab version with everything you need.
Both plug-ins support core IDE features you would expect to find. The code intelligence is rock-solid, pops up when you want it, and displays all the information you need for classes, methods, and arguments.
Figure 1 shows PHPEclipse running on Mac OS X. On the left side is the project view with the files in the project. Below that is the class view, which shows any classes I’ve defined. In the center is my code. I can have multiple files open in multiple tabs simultaneously. On the right side are panels for debugging and browsing. This is the stock PHPEclipse user interface.
Figure 1. PHPEclipse on OS X
Figure 2 shows the PHP IDE Project plug-in from the Eclipse Foundation in action.
Figure 2. PHP IDE Project on OS X
If you can’t tell the difference, I don’t blame you. The two look very similar because both rely on the Eclipse platform to present their code browsing and intelligence features. Consistency among Eclipse plug-in GUIs is a good thing.
I did not find that either plug-in locks you into a particular Eclipse project. You can always change one plug-in for another. In my limited testing, I preferred the PHP IDE Project plug-in because it felt better integrated to me, and the performance of the code intelligence features seemed snappier. Try both to see which you prefer.
The downside to both plug-ins is that because Eclipse can be used for almost any programming language, the UI is not tailored to PHP. As a result, Eclipse’s terminology is a bit alien at first. If you’re new to Eclipse, this results in a steeper learning curve for these plug-ins than the other IDEs. On the other hand, if you know Eclipse, you’re ahead of the game using either PHPEclipse or PHP IDE Project.
The big upside to Eclipse and these plug-ins? They are free. As in free. And stable. And reliable. Oh, did I mention they’re free?
Next up is ActiveState’s Komodo IDE. This IDE runs on Windows, Mac OS X, and Linux, and it supports the usual open source language suspects — Perl, PHP, and Ruby. The code intelligence engine is solid. It scans all your language installations to find custom extensions, such as PEAR modules. On the project side, it supports integration with CVS, Subversion, and Perforce, as well as allowing for direct FTP transfer of code to the server.
Figure 3 shows Komodo running on Windows. A class view is on the left, and the project view is on the right. Dominating the center is the tabbed code view. To the bottom are the breakpoints for the debugger, the command output, and so on. As with all these systems, you can significantly customize the UI to match your preferences.
Figure 3. Komodo running on Windows
Komodo is a commercial product. At the time of writing, the IDE was available in personal (US$29.95) or professional (US$299.95) versions. One of the unique features of it is its regular expression debugger. That alone is almost worth the price of admission if you’re new to regular expressions or if you use advanced regular expression features.
On the downside, there’s no database integration that I could find, and I encountered some small issues with the code intelligence not always wanting to pop up. Overall, however, Komodo is a robust, feature-rich, and reliable IDE for PHP.
PHP Designer takes a different tack from the other IDEs. Sure, it supports limited code intelligence. However, its focus is on further enabling the design aspect of the PHP Web application. This is evidenced by its integrated browser being adorned with pixel rulers to help in positioning elements on the page.
Figure 4 shows the coding side of PHP Designer in action.
Figure 4. PHP Designer on Windows
NuSphere’s Windows-only PhpED is easily the most feature-laden of all the IDEs presented here. It’s got a great internal debugger and gets extra marks for putting a debugging tool bar into Microsoft Internet Explorer® for easy access to page debugging.
Figure 5 shows PHPEd developing a PHP application in Windows. On the far left is the file view of the project. To the right of that is the class view, and to the right of that is the code view. Below are status read-outs. In case you haven’t noticed yet, all these IDEs follow the same basic design aesthetic.
Figure 5. PhpED on Windows
Standout features of PhpED include a great debugger, excellent database access, good code intelligence features, and integrated PHP help. PhpED prices range from US$119 for the basic version to US$495 for the professional version. A trial version is also available.
Figure 6. PHPEdit on Windows
To help with deployment, PHPEdit connects to CVS and Subversion, as well as FTP and its own proprietary ezDeployment system. To help speed development, in addition to the code intelligence features, the IDE has an excellent canned template library of code samples to which you can add on. The evaluation version of PHPEdit is available at no cost, but to get the real deal, it will cost US$89.
Finally, we come to Zend Studio, listed last here only because it starts with a Z. It should probably be first on your mind. Why? Because it comes from Zend — the folks behind PHP. Oh, and it’s good. It runs on the Big Three: Windows, Mac OS X, and Linux. And it comes with absolutely everything you need: PHP V4, PHP V5 — the whole deal. Yes, it takes a long time to download, but it’s worth it.
As an IDE, Zend Studio is top-notch. It has all the code intelligence features you could want on both the built-in libraries and on custom code. It also has excellent debugging that’s a snap to set up. To get your code into the repository, Zend Studio connects to both CVS and Subversion. To get your code to the server, there’s integrated FTP. Zend Studio, looking fittingly handsome on the Macintosh, is shown in Figure 7.
Figure 7. Zend Studio on the Mac
As with some of the other IDEs, code snippet support is built in to make cranking out the code easy. The IDE also integrates directly with your database to give you insight into the available tables and fields.
The standard edition of Zend Studio is US$99, and the professional edition is US$299. Some of the features I talked about here are held back from the standard edition. A trial version of Zend Studio is available at no cost.
With so many excellent IDE options out there — some of which are even free — I can’t see any reason not to give one a try, particularly if you’re a professional. You can have either your company or your personal consultancy expense a portion or all the cost of any of the commercial products. When you consider the time wasted just on using
echo statements to debug your code versus using an integrated debugger, the purchase price of this IDEs is a no-brainer.