PHP developers are generally a passionate bunch. They have strong feelings about their favorite language for Web applications development and the comparative failings of other approaches. These emotions usually extend to a specific development tool -- a text editor. Whether it's
vim, HomeSite, TextEdit, or BBedit, most PHP coders have their favorite tool that they swear by.
I know that for me, however, this geeky love fest can turn ugly when it comes time to debug PHP code. Text editors, no matter how well they're designed, are not equipped to help you track down a misspelled variable name, a misplaced argument, or a malfunctioning function. I don't think anyone enjoys the process of sprinkling PHP code with
print_r statements and re-loading pages over and over.
My guess is that some developers who might have chosen PHP because of its power and ease of use went with other languages because PHP lacked an IDE. This need no longer be the case, as no fewer than three companies produce IDEs for PHP (Zend, ActiveState, and NuSphere). This article will give an overview of one of these products: NuSphere's PHPEd.
PHPEd, like all IDEs, is designed to do lot more than any text editor. If an IDE works well, it should cut your development time. So while the transition from some beloved text editor to an IDE might be difficult as you pine for your old macros and shortcuts, in the end it should be worth the time you invest getting to know the new tool.
Using PHPEd, your major time savings will come when debugging code, but since you will spend much of your time typing PHP, I'll start by looking at PHPEd's text editor. Note that PHPEd is currently a Windows-only tool. However, the word is that a Linux version should be released soon. If you're working on another OS, look into one of the other IDEs.
You'll find that PHPEd competently performs all of the tasks expected of a text editor: its syntax highlighting is fine, and it automatically inserts closing quotes, parentheses, brackets, and curly braces. Figure 1 shows what some syntax-highlighted code looks like in PHPEd. Note that the colors are configurable, which was good for me, because I did not find the default colors aesthetically pleasing.
As you type function names in PHPEd, the text editor displays a function reference, complete with return value and arguments, as shown in Figure 2. If you're currently using a basic text editor for PHP, you might find that this simple feature saves a lot of time, as you don't have to pull open a page from the PHP manual every time you forget the order of arguments in a function.
Similarly, when you type a dollar sign ($), PHPEd automatically displays a window that lists all of the variables that have previously been defined in the active script. At this point, the listing is a bit too extensive, as variables that have been deleted continue to appear in the listing.
PHPEd's debugger is clearly the tool's major selling point. To understand how useful a debugger can be, consider an example that can be found in most every Web application: you collect some data via browser form inputs that need to be validated, manipulated (perhaps by stripping tags, changing special characters to HTML entities, etc.), and then inserted into a database. What do you do if the process does not go as you expected and there's an error in the code that you need to track down? It's possible that the error lies in any one of several files or any one of many functions. Without a debugger, all you can do is insert
echo statements at the likely problem spots and re-run the script. This tedious process can go on for a while before you find the source of the problem.
The PHPEd debugger allows you to follow a script, through all of its includes and functions, and track the values of variables at each stage. With the debugger you can step through the script and at each step, you can see how variables are responding to conditionals and functions.
There are two ways to view variable values in the debugger. You can put a "watch" on a variable name and see how the value changes in the debugger window. Or you can simply roll your mouse over a variable and see the value at that stage of the script. Figures 5 and 6 show both of these methods.
The debugger also allows you step over and out of portions of your application, allowing you to focus in on only the problematic portions of your script.
PHPEd's debugger is not perfect. Array values don't always display properly in the debugger window, but it does deal with scalar variables and objects well.
NuSphere is primarily a database company that has been working with MySQL. So it should be no surprise that PHPEd comes with tools that help integrate PHP with the MySQL database. If you are a MySQL user, these features are pretty convenient, as you can get information on your schema and data without having to open up
phpMyadmin or the MySQL command-line client.
For starters, you'll be able browse through all of the databases and tables available to your server. From the database window (Figure 7), you can copy database and table names and paste them into your scripts, thereby cutting down on potential typing errors.
Additionally, you can look at the details of specific tables -- including table structures, field names, data types, and live data. Figures 8 and 9 show three different views of a single table in PHPEd.
You can also run arbitrary queries against a MySQL database. There's no longer a need to open a separate application when it comes time to debug queries. You can simply paste the query into a form and see the data that is returned. (Figure 10).
It would be nice for many PHP developers if PHPEd could integrate with other databases -- PostgreSQL support, in particular, would be nice. IDEs on other platforms support helpful features like dynamic query building that are not available here.
At US$299, PHPEd is probably more expensive than your current text editor, but if you're looking for a tool that can help you develop PHP faster, PHPEd may well be worth the investment. The text editor, debugger, and MySQL features will make life just a bit easier and the coding day just a bit shorter.
Jay Greenspan is a contributing author for Apple Developer Connection.
Return to ONLamp.com.
Copyright © 2009 O'Reilly Media, Inc.