PHP DevCenter
oreilly.comSafari Books Online.Conferences.


Using Zend Studio for PHP Programming
Pages: 1, 2, 3, 4

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


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.


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

Pages: 1, 2, 3, 4

Next Pagearrow

Valuable Online Certification Training

Online Certification for Your Career
Earn a Certificate for Professional Development from the University of Illinois Office of Continuing Education upon completion of each online certificate program.

PHP/SQL Programming Certificate — The PHP/SQL Programming Certificate series is comprised of four courses covering beginning to advanced PHP programming, beginning to advanced database programming using the SQL language, database theory, and integrated Web 2.0 programming using PHP and SQL on the Unix/Linux mySQL platform.

Enroll today!

Sponsored by: