ONLamp.com    
 Published on ONLamp.com (http://www.onlamp.com/)
 See this if you're having trouble printing code examples


Using Zend Studio for PHP Programming

by Michael J. Ross
03/11/2008

Desktop application developers — using Java, C++, or any similar language — are accustomed to being able to choose from a number of powerful integrated development environments (IDEs), each of which typically brings together the functionality of a programmer's editor, a source-level debugger, source code management, a built-in FTP client, and more. As with any robust tool, these IDEs can take some getting used to, and a fair amount of time to thoroughly learn all of their features. But for most programmers, it is time and effort well invested, because it pays dividends in the form of faster development of more solid code.

Web developers, on the other hand, have not enjoyed an equally long history of project- and sanity-saving IDEs. But during the past several years, the tide has turned, and now web languages such as PHP are receiving a lot more software vendor attention.

One clear example of this is Zend Studio, created and distributed by Zend, headquartered in Cupertino, California. The organization bills itself as "The PHP Company," and not without reason, because it has a history of supporting the language, since 1997, including development and contribution of the Zend Engine, which is now PHP's execution engine.

Zend Studio for Eclipse is the company's latest update of its PHP IDE, and carries a version number of 6.0. As a foundation, it uses Eclipse, an extensible open source platform for software development that is growing in functionality and widespread usage every year. It also utilizes the PHP Development Tools (PDT) framework.

Zend Studio version 6.0 represents a new generation of the product, encompassing all of the functionality of version 5.5, which will continue to be maintained by Zend, with maintenance release version 5.5.1 coming out in January 2008. Jeff Koo, who is involved in Zend public relations and kindly provided information on both products, noted that Zend plans to continue maintaining version 5.5, to allow customers to make the transition on their own schedule. Version 5.5 will be the last non-Eclipse release of Zend Studio.

Product Editions, Requirements, and Pricing

Zend Studio comes in two editions: Standard and Professional. The Standard edition offers a complete source code editor (that supports PHP 4 and 5) and an interactive debugger for local PHP scripts. The Professional edition adds a host of additional capabilities, including code analysis, optimization, version control, and source management — covered in more detail below.

In this review, we will examine both editions — often comparing one to the other — but focus on the Professional edition, since it is the future product path.

In terms of size on disk, Eclipse itself is certainly not a small product, with the installation files of its various flavors currently varying from 63 MB to 153 MB. Including Eclipse and PDT into this newest version of Zend Studio is likely the primary reason why its installation file is much larger than that of version 5.5 — namely, over 290 MB versus about 68 MB. When installed on disk, the former consumes about 433 MB, while the latter consumes 157 MB. Unlike the system requirements specifications for most software applications, the Zend site does not mention anything about disk space usage.

However, the system requirements page does specify that Zend Studio runs on Windows 2000, XP, 2003, and Vista (32 bit only), Linux x86 and x86-64, and Mac OS X 10.4 with an Intel x86 or a PowerPC G4 or G5 processor. The system requirements for Zen Platform are also provided.

The cost for the Professional edition, for a one-year support subscription, is normally $399 USD, and $717 for three years. The introductory prices, as of this writing, are $299 and $498, during the first 30 days after the January 22, 2008 release. The Standard edition will continue to be priced at $99, and does not include technical support, though purchasers of the product can always upgrade to the Professional edition. For both editions, customers can choose either version 5.5 or 6.0, depending on whether they are interested in using Eclipse.

Installation and Start Up

After downloading the Zend Studio installation file for your particular operating system, there are several steps to installing the product. The two major ones are Configuration and Installation. In the former, you can elect to have the Zend Firefox and Internet Explorer toolbars added to your browsers. You can specify the target installation directory, as well as which file extensions to associate with Zend Studio. With this latest version of Zend Studio, installation was more straightforward than that of 5.5, which involved a 13-step process. In addition, installation of the full PHP manual is no longer optional; but having that reference information so readily available is certainly worth what little extra space it consumes. Lastly, in version 5.5, installation of Zend Core (which comprises additional extensions, libraries, remote debugging, etc.) and Zend Platform (a PHP application server) is optional.

When it starts up, the Eclipse version attempts to contact the IP address 192.168.255.255 using port 4321. This may be part of the product's license protection. At least during the 30-day evaluation period, disallowing the connection did not appear to impede its functionality in any way. Also, at start up, Zend Studio (both versions) offers a usage tip; these can be disabled if so desired. In addition, version 5.5 first checks for earlier versions of the product; version 6.0 did not appear to do so.

If you intend to do any debugging of local PHP scripts, as most users will, and you sometimes shut down your local web server (for whatever reason), verify that the server is running, prior to doing any work in Zend Studio — otherwise you can receive a cryptic error message, "The selection cannot be launched, and there are no recent launches." A more descriptive message, such as "Web server not running," would be less confusing — particularly if the user has just selected (highlighted) some lines of code.

User Interface and Preferences

As with any IDE, the clarity and organization of the interface is critical to its usability and whether or not the programmer will continue to use the new tool, and not revert back to their previous development environment.

First we will examine the Zend studio 5.5 interface, and briefly discuss how it has changed with the Eclipse version. In both versions, the user interface has several components, consisting of panels, termed windows, located underneath the menu and toolbars. The windows can be adjusted in size and location, but by default the central one, the Editor window, contains the current PHP script being debugged, with the others arranged around it.

Zend Studio 5.5 - User interface
Figure 1. Zend Studio 5.5 - User interface

In version 5.5, the non-Editor windows (in counter-clockwise order starting in the upper left) are by default as follows: The File Manager allows one to work with files, projects, and SQL Server. It should be essential for large-scale projects, for which keeping track of their many components can either ease or undermine project management. Below that panel is the Inspectors window for the file, project, and PHP inspectors. At the bottom left-hand corner one finds the debug Messages window. To the right of that is a Debug window for monitoring variables, watchpoints, etc. As with any robust IDE, being able to easily step through code and watch the variables change value,alone makes it worth the price of entry. To the right of the code window is the aforementioned Debug Output window — enough to make just about any developer wish for a larger screen.

After carelessly adjusting some of these windows and making a bit of a mess, I searched in vain for a way to restore the windows to their default layout. I tried restarting Zend Studio and not saving the current workspace as a project, but that did not do the trick. Some sort of View > Restore Default Layout menu item would be a handy option for such situations. Admittedly, the windows can be dragged to new locations using a handle in each one's upper left-hand corner, but the behavior was fairly erratic, and I never was able to restore the initial layout.

These various windows can be seen in action when running the built-in Debug Demo, as shown in Figure 2.

Zend Studio 5.5 - Debug demo
Figure 2. Zend Studio 5.5 - Debug demo

In version 6.0, you are initially presented with a welcome screen, shown below. Choosing one of the links to start a new project brings you to the main development window, as illustrated below when running the Debug Demo.

Zend Studio 6.0 - Welcome screen
Figure 3. Zend Studio 6.0 - Welcome screen

Zend Studio 6.0 - Debug demo
Figure 4. Zend Studio 6.0 - Debug demo

With this new Eclipse version, the user interface has an appearance that experienced users will likely consider cleaner and less busy — with initially six fewer toolbar icons than before, although there is one more menu item. The colors are lighter now, and gives the interface an overall more elegant look. Space is saved by locating window-specific toolbar icons in the same ribbon as the window's tab, thereby reducing the icon clutter under the menu bar.

Before creating any project, or working with an existing one, you should probably make an effort at setting your preferences. These can always be adjusted in the future as you learn more about the product's capabilities and how you want to make best use of them. In version 5.5, these are accessed via Tools > Preferences. As shown in Figure 5, you can set preferences for Zend Studio's desktop, editor, code completion, colors and fonts, debugger, Zend Platform, keymaps, file types, templates, source control, dialog boxes, and SQL. For instance, programmers who have already internalized an extensive list of personal keystrokes for the many actions they perform within their favorite editor, will be able to set and save those same keystrokes within Zend Studio's editor. Unfortunately, unlike some editors, it does not support multi-part keystrokes (for instance, using "Ctrl+G L" to go to a line).

Within the Preferences > Dialog panel, you can indicate what Zend Studio dialogs you wish to see. Lastly, the SQL panel allows you to specify such settings as whether to use the LIMIT keyword, the maximum entries per page, and others.

Zend Studio 5.5 - Preferences
Figure 5. Zend Studio 5.5 - Preferences

In version 6.0, preferences are accessed from the "Windows" menu. With this Eclipse version, there are far more preference options — more than can be discussed here. In general, I found the version 5.5 options to be more straightforward and less overwhelming; the significantly greater number of options is no doubt a result of the product being based upon Eclipse.

Zend Studio 6.0 - Preferences
Figure 6. Zend Studio 6.0 - Preferences

Fortunately, version 6.0 has a way to limit the options to those that match some text that you type into the entry field just above the option tree; see "type filter text" in Figure 6. For instance, if you are having difficulty finding where to change the code formatting standard, simply type in "format", and the options will immediately be limited to only those shown in Figure 7.

Zend Studio 6.0 - Preferences filtering
Figure 7. Zend Studio 6.0 - Preferences filtering

Editor

Zend Studio's built-in editor has all the functionality that veteran coders have come to expect of modern programmer's editors: multi-document editing with tabs, stream and paragraph text selection, multiple undo and redo, multi-line tabbing in and out, automatic matching brace creation and coloring, smart-indenting and outdenting, code-folding, and code block commenting.

Searching and replacing can be done for text in multiple files, locally and remote, via Edit > Find/Replace. It supports regular expressions. In addition, text searching in PHP files can be limited to classes, functions, or constants, and even to specific workspaces and working sets, via Search > Search. It enables you to remove or rename PHP elements in a specific file, making it more context sensitive, and thus avoiding the problem of matching and perhaps accidentally replacing, for instance, a class name that just happens to match some text in a comment. This refinement can be especially valuable when performing code refactoring. Also, the preview capability makes it easier to safely change an element's occurrences in one or more files. The wildcards * and ? are supported, but apparently not regular expressions.

The editor's syntax highlighting and checking capabilities are excellent, and fully customizable. However, in version 6.0, it can be difficult at first finding where to make the changes within the Preferences tree (PHP > Editor > Syntax Coloring). You can even specify your preferred whitespace style (PHP > Editor > Formatter).

Code completion is taken one step further, in the form of what are termed "templates" — snippets of code commonly found in most programs. Templates can contain placeholders, such as "${name}", replaced with a value on the fly, when you add the template to your code. For instance, by default, the key "cls" triggers the addition of a template for creating a class statement: "class ${name} { function ${name}() { ${END} } }". Even better, you can create your own templates, and assign them to any available keys.

Zend Studio's editor is quite impressive. There were only a handful of features missing that are usually found in the more advanced editors and IDEs: recordable macros, keystroke repetition, rectangle block text selection, and text joining and reflowing. However, only the first of those would likely see much demand by programmers.

Debugger

If the editing capabilities previously discussed were all that Zend Studio provided, then any top-notch programmer's editor, such as jEdit, would be sufficient. But it is the graphical debugger that is usually enough to convert any new user to an IDE, and allow one to purge all those now-unneeded 'echo' statements.

Zend Studio's debugger provides all of the power seen in similar products, including step control and breakpoints. Especially appreciated is the automatic listing of all variables in scope, as opposed to the approach taken by inferior IDEs that require the programmer to key the variable names in every time, or expand arrays to show individual elements. In addition, string lengths are displayed, which can save even more time — especially when debugging code that does a fair amount of text processing and comparison.

Also, both versions 5.5 and 6.0 of Zend Studio support internal and remote debugging, i.e., PHP scripts on your local Web server versus a remote server. The remote capability could be a lifesaver in situations where code that runs fine in your local environment, is exhibiting one or more bugs after being deployed to a remote machine.

If you are new to Zend Studio's debugger, you can ease into it by running the Debug Demo, shown earlier, which displays some sample worker data in an HTML table. As you step through the sample PHP code in the Editor window, you see the corresponding results, step by step, in the Debug Output window, which offers two views. In version 5.5, they are named "Text" (showing the HTML code) and "HTML" (how it would be rendered in a Web browser). A better set of names would have been "HTML" for the first view and "Web" for the second. In version 6.0, they have been improved to "Debug Output" and "Browser Output."

The debugger generally works smoothly. However, while trying the demo in version 5.5, I discovered that the "Go to Cursor" command was not behaving entirely as I would have expected. With the edit cursor on a line of code that comes after a function call, choosing the "Go to Cursor" command did not move the debugger up to that cursored command, but it instead stepped into the preceding function. The cause of this behavior was not evident. The "Go to Cursor" command was not seen in version 6.0.

File and Version Management

One of the most critical pitfalls of any software development project — proportional to the number of lines of code and the number of programmers — is controlling the source code. This includes organizing it so existing components can be quickly found, and new components can be quickly placed in their optimal location. Moreover, one needs to be able to save and track revisions to the code.

Zend Studio makes it possible to do so, without leaving the environment, with its tools for creating and managing projects; searching through code based upon projects; built-in browsing of projects, code, and objects; and hooks to version control systems. Source code for projects can be tracked using CVS or Subversion. For both version control systems, you can specify the application path, desired messages, and text styling of the file statuses, including different colors.

Both versions of Zend Studio can display the color-coded differences between two files, which can be a godsend when dealing with forked code (intentional or otherwise!), attempting to determine the functional differences between two or more versions of the same code, and possibly trying to merge them back into a single trunk.

For transferring files between your local and remote servers, version 5.5 has a built-in FTP client (Files > Add FTP Server), which supports both FTP and SFTP, and saves all of your connection settings for future use. Version 6.0 provides FTP and SFTP support through the Remote System Explorer (RSE) plugin (which I did not test).

Code Generation and Samples

Busy programmers are always seeking ways to get more done with less effort and in less time, including creating code that will itself create code. Zend Studio adheres to this laudable principle in several forms: code creation wizards, code snippets, code expansion, and templates. Those last two were discussed earlier.

Zend Studio's wizards can be used to automatically generate source code for classes, interfaces, and their methods. For instance, when you request Zend Studio to create a new class or interface, it will immediately insert the bare bones structure of the particular type of item. Simply right-click anywhere in code, and from the context menu choose New > Class. Within a class for which the instance variables have been defined, it can insert getter and setter methods (as illustrated in Figure 8) — thus automating a tedious step in object-oriented development. In a phone conversation, Yossi Leon, Zend Studio product manager, noted that users of the product have applauded its code generation capabilities.

Zend Studio 6.0 - Generate getters and setters
Figure 8. Zend Studio 6.0 - Generate getters and setters

Zend Studio offers "Code Galleries", which are groups of pre-written code snippets designed to be easily inserted into your own scripts. By default, Zend Studio provides a User Code Gallery, to which you can add your own code snippets, and the Zend Code Gallery, which requires registration to the Zend Network. In version 6.0, code snippets can be accessed from the Code Gallery view, via Window > Show View > Other > PHP Tools > Code Gallery.

Testing and Optimizing

With the growing interest in agile software development methodologies, Zend Studio for Eclipse makes it even easier to do test-driven development, specifically, unit testing of one's PHP code. It also provides greater integration with PHPUnit in Zend Studio's user interface. Moreover, the wizard can create for you a skeleton for your test cases for the particular class you are working on. Eventually you get a view to summarize all the tests, and it will provide a summary of any failures, with indications as to exactly where the problems occurred.

Zend Studio 6.0 - Unit testing
Figure 9. Zend Studio 6.0 - Unit testing

When attempting to optimize one's PHP code, one of the most valuable tools is some sort of profiler, which reveals how much time is being consumed by each part of your code. Zend Studio has a built-in profiler, illustrated in Figure 10.

Zend Studio 6.0 - Profiler
Figure 10. Zend Studio 6.0 - Profiler

Browser Toolbars

It was noted earlier that during the installation process, you can elect to have Zend Studio toolbars added to your Web browsers. At this time, the two supported browsers are Firefox (shown in Figure 11) and Internet Explorer.

Zend Studio 6.0 - Firefox toolbar
Figure 11. Zend Studio 6.0 - Firefox toolbar

The first icon launches Zend Studio. The second begins debugging of the page currently open in the browser. If Zend Studio is not already running, it attempts to launch it. Unfortunately, it assumes that the product was installed in C:\Program Files\Zend\ZendStudioClient-5.0.0\bin\.

Zend Studio 6.0 - Browser toolbar error message
Figure 12. Zend Studio 6.0 - Browser toolbar error message

Note that "Extra Stuff > Preferences" refers to a menu item in the browser toolbar itself, not in Zend Studio proper. Users who wish to fix the configuration setting, and who search for it in the program, will be unable to find it, and it is apparently not even mentioned in the online help information.

The third icon is a drop-down menu for debugging the current page, the next page, all the forms on the current site, and all the pages on the site. At first it seemed odd that of all five icons in the toolbar, it is the only one unnamed. But the logical name would be "Debug," which is already used by the third icon. This suggests that those two menus should probably be combined into one.

The fourth icon is for profiling the current page. Even after modifying the configuration setting to point to my Zend Studio executable, neither this one nor the second icon worked as expected.

The last icon, "Extra Stuff" contains the toolbar settings, as well as links to Zend and non-Zend PHP sites. Thus, a much better name for the menu would be "Resources."

The toolbar, like Firefox itself, also has a built-in search facility, for searching the Zend.com site, the Zend knowledge base, PHP.net, and the entire Web via Google.

Zend Framework

PHP projects are increasingly being built upon open-source frameworks, including Zend Framework. Zend Studio has extended support for Zend Framework — facilitating the creation of Zend Framework project directories, etc. It is built into the Eclipse version of the product, and will be added to the 5.5 version with the release of 5.5.1.

Zend Studio 6.0 - Zend Framework
Figure 13. Zend Studio 6.0 - Zend Framework

Support

Most open source IDEs suffer from — and make the user suffer through — inadequate support, usually just pointing the frustrated user to a mishmash of useless "documentation" or a forum seeing little traffic. Zend Studio, on the other hand, is bolstered by an adequate amount of helpful resources. The built-in help information is extensive and completely indexed, and it offers full text searching, with highlighting of search terms. It also has the filtering capability discussed earlier in regards to limiting the preference options. Yet even with the ability to filter help entries, it would likely be of great value to the new user to have a section devoted to quick start guides.

On the Web, Zend's support page offers a knowledge base, forums, and FAQs. The Resources page has links to some Release Notes, a User Guide, an Installation Guide, a Datasheet, a Quick Start Guide, and the Official Keymap. Several informative videos for version 6.0 can be found Zend's Demo Videos page.

Furthermore, licensed users can obtain technical support online, by submitting a ticket to Zend's Technical Support Team.

Conclusion

Zend Studio, especially the Eclipse version, has a great many capabilities — more than can be deeply explored in a single article. Not discussed here are the built-in tools for code refactoring, database tools, working sets, and integration with external Zend tools, such as Zend Guard. Interested readers are invited to test these capabilities on their own, and see how much value they add to one's unique development needs.

One advantage that Zend Studio has over some if not all similar PHP-capable IDEs, is that it has a PHP interpreter built into it. As a result, you avoid the installation hurdle of informing the IDE as to where on your computer it can find a PHP executable. This may sound trivial, but one major non-Zend IDE that I tested refused to recognize a perfectly working PHP executable as valid — thereby making the IDE unusable. In the case of Zend Studio, it has the Zend Engine built in, and both versions 5.5 and 6.0 support PHP 4 and 5, while version 6.0 is more customizable, and even allows you to assign your own interpreter and own extensions, if so desired.

Aside from the minor problems and suggestions mentioned above, Zend Studio is a powerful, impressive, and potentially valuable IDE that should be tried by all PHP programmers who want to make their development efforts as painless as possible, and are willing to invest the time and effort to learn how Zend Studio can do just that. Zend Studio is strongly recommended to individuals and teams building PHP applications.

Michael J. Ross is a freelance web developer, working primarily with Drupal.


Return to ONLamp.

Copyright © 2009 O'Reilly Media, Inc.