The aim of an IDE is to give you, the developer, all the support and help you could possibly need to develop robust applications efficiently and accurately. The number of different ways to do this varies wildly from product to product, but there is one thing which you should look for in all of them. As with any software you use, one of the first things to decide before forever developing in one environment is whether that environment benefits you. In other words, does the IDE make it easier for you to develop your applications? If so, then it stands to reason that you should really be using that product as your development environment of choice. Simple as that.
Having simplified the argument to whether you think the DE of your choice is performing its job ignores one important fact, which you should bear in mind. As would be true with any other software, it may take some time to fully utilize the power inherent in these IDEs, so it is worth investing the hours finding your way around them. To that end, the following few sections should give you an idea of what to expect.
Zend's offering should arguably be your first stop when looking for an IDE to use assuming that you are happy to fork out the $249 or so that it will set you back. Of course, before purchasing anything, you should really take a close look at it, and you can download a free trial version from the Web site http://www.zend.com/store/products/zend-studio.php.
As of this writing, the current release version of Zend Studio is 3.5.0, which now includes full support for PHP 5. It is available for the Windows, Linux, and Mac OS X platforms.
If you are not familiar with IDEs, they can appear a little daunting at first. Keep in mind that they are here to help, not to confuse things. In this case, the Zend Studio is more than an IDE; it also provides you with features apart from the Development Environment. The server version comes with a precompiled version of PHP and Apache, for example. For the purposes of this appendix, we concentrate mainly on the Zend Development Environment (ZDE), which is the tool that allows you to manage and develop your code. With that in mind, the first screen you are presented with in the ZDE, after you have downloaded and installed it, is much like Figure B-1.
Before doing anything else, click Tools Preferences Debug and then click the PHP5 option. You will run into all sorts of problems if the debugger is using PHP4. With that done, you are more or less ready to begin using the development environment. Plenty of documentation covers all the functionality in ZDE, so we won't cover everything exhaustively. Instead, we go through the most important features to give you a broad idea of what the ZDE is all about. We leave it to you to play around with the ZDE and make your mind up about whether to adopt it.
At the highest level, the DE has two tabs that allow you to manage your file system and your PHP projects. Looking at Figure B-1, toward the top left of the screen, you will notice that the File System window is the one with focus. You can use this to search for files using the drop-down list immediately below it to filter your results.
The Project window allows you to navigate any given project you are working on and perform various actions such as adding and removing files from a particular project. It is probably prudent for us to mention that the Project menu item on the ZDE's main menu allows you to create, open, save, and close projects.
Use projects to define a common working environment for files in any given project. For example, you may wish to have a specific debugging setup while working on a new site for a client, and placing the site's files into a project allows you to do this in an efficient manner.
Obviously, you would expect certain editing abilities to come with a full DE like this, and certainly, it has some neat features. The editing window is the large, central one shown in Figure B-1 earlier, and it contains a host of tools that are designed to make coding easier. One of the major features is code completion, which is available for both PHP and HTML. This allows you to display pop-ups of function parameters, declared functions, keywords, and constants. Figure B-2 shows an example of the pop-up displayed when you begin typing in a PHP5 array function.
As with most aspects of this DE, code completion is configurable, and you can check out the options by choosing Tools Preferences Code Completion. Figure B-3 shows you the screen presenting your options.
The Preferences window provides you with many other configurable settings, such as editing and debugging options.
The DE also provides you with code indentation facilities. You can either chose to indent your code manually, as you type, or all at one time a nice feature that makes life a bit easier. If you click the editing tab of the Preferences menu, you will see a list of all the editing features that are available to you. One of the more useful ones is the matching brackets feature, shown in action in Figure B-4.
Placing the cursor immediately before the beginning elements or immediately after the closing elements causes the editor to highlight the matching element. A useful trick here is to press Ctrl+M to jump between matching elements to avoid tiresome scrolling. See the Go To Main Menu option for more navigation shortcuts.
Templates are also available to help speed up otherwise repetitive tasks. There are plenty provided as standard, but you can also add your own or even modify the ones that are already there. You can view the available templates by going to the Template tab of the Preferences window. Each template has a given key that denotes its specific template. For example, Figure B-5 shows the results of typing my into the Editor window.
The top four options are all templates that come with the DE. If you click one of them, the template code assigned to that key is automatically added to the Editor window. Figure B-6 shows the results of clicking the second option.
A bunch of other useful editing features are available, ranging from HTML tag shortcuts to syntax error highlighting. The only way to really learn your way around these is to play with them. The help files do a good job of outlining all the DE's features, so use this to find your way around. Let's move on and look at another useful feature of the ZDE.
Recall from Figure B-1 the window on the bottom left of the ZDE, called Inspect. This comes with three options: File, Project, and PHP. The first option gives you a collapsible list of all the elements of the file, which has focus in the Editor window. Figure B-7 shows an example of this in action:
You can use this for navigation if you wish. Double-clicking any of the elements listed in the Inspect window will take the cursor directly to that piece of code in the source file.
You can look at things from one level up by clicking the Project tab. This gives you an overview of everything in the current project. It acts pretty much in the same way as the File window in that you can click any file or displayed element of that file in the Project window and it will be opened for editing in the main window.
The final option PHP gives you a list of all the PHP functions and their syntax. Of course, you may wish to know a little more than just their usage, so if you highlight the function in the Inspect window and press F1, a slightly more in-depth information file will pop up in a browser window. Incidentally, this also works for PHP functions within your Editor window simply highlight the function you wish to learn about and press F1.
For brevity's sake, we assume that you have everything running on one machine (in other words, you have downloaded and installed the Zend Studio Client) so that you can debug your applications locally. It is possible to set up a multiuser debugging environment by installing the Studio Server package on a central, nonlocal server, and you should consult the documentation for more information on this.
One of the biggest advantages you can derive from using a development environment is making use of the innovative debugging features they provide. Plowing through error log files is one way to do it, but that can be quite clumsy in comparison to the more sophisticated methods available. The internal debugger has a list of features designed to help you keep tabs on exactly what is happening in your code. Specifically, its main function is to provide you with:
Program flow monitoring
A debug window
A debug messages window
Let's look at these in some detail. One of the first things with which you need to familiarize yourself is how to go about debugging your code. The ZDE provides several methods for moving from place to place. Some involve setting breakpoints; others simply trace the flow of the program step by step. You will notice a set of arrows (shown in Figure B-8) that can be used for stepping over, moving between breakpoints, or simply running your code.
Note that the final icon you see in Figure B-8 runs the code analyzer. The analyzer's main job is to help determine where errors may be located in the code open on the Editor screen. Add a syntax error to your code and run the analyzer on it to see how it works.
After you have the hang of stepping over your code or following a script's execution, you can use these to find out valuable information on the state of your code. For this, though, you need the Debug window. The Debug window, located by default on the bottom right of the ZDE, provides you with five options to monitor and manage your project's debugging. From here you will be able to view the value of variables, the position of watches, the stack trace, the position of breakpoints, and the buffer. All these come in handy depending on what it is you are trying to determine about your code.
For example, we have stepped over the execution of a very simple PHP script to demonstrate how the Variables tab shows you information on all the variables associated with your code (including the global ones). This is shown in Figure B-9.
Notice that the fifth line in the Editor window is highlighted. This is because, at present, the debugger is stopped at this point in the script's execution. The values you see in the Variables window are the values at this particular point in the program's execution. If you know the piece of code you want to inspect, you can forgo stepping over it line by line and place the cursor on the line you wish the debugger to go to. Clicking the Go to Cursor (fifth, from left to right in Figure B-9) button will take you straight there.
The next tab along is the Watches tab. You might find that you want the debugger to keep an eye out on a number of different pieces of code. If this is the case, then set watches for the code elements you wish to trace. We highlighted the $answer variable in our code example shown previously and clicked Debug Add Watch. This time, stepping over the program's execution using the debugger gives the following, not entirely unexpected, results (Figure B-10).
Tracking the execution stack is also a useful way of determining where you are in your code. The Stack tab allows you to view where you are in the program's stack. This can be helpful because if one part of your code calls a function, the program's execution leaves the current place to go off and run the called function. If the function itself makes use of other functions, then the program's execution heads off again to go execute those. Being able to determine exactly where you are in all this is where the Stack tracking capability of the debugger comes in.
Figure B-11 shows an example of the Stack window being used to track a simple script that has two functions.
To get the debugger to stop where we want, we need to set breakpoints. Breakpoints are simply delimiters that tell the debugger to freeze execution as is so that you can look over whatever you need to. In Figure B-11, two breakpoints have been set by clicking the line number in the Editor window. This causes the selected line to be highlighted in pink (although you won't see color in the screenshot, you can see which lines are highlighted) and means that this is now a set breakpoint. Clicking the Breakpoint tab will verify this for you (see Figure B-12).
Finally, if you are making use of PHP's output buffering functions, then the final tab, Output Buffer, is just for you. Basically, it shows whatever is in the buffer, and we tested it with the following script (Figure B-13) to demonstrate.
With that done, two things are left to mention. The first is the Debug Messages window, which is located, by default, to the left of the Debug window. It displays notices, warnings, and errors that crop up during the debugging of your scripts. Double-clicking the messages in the Messages window allows you to locate their source quite easily by sending the cursor to them in the Editor window.
Finally, the ZDE also renders your script's output in the Debug Output window. This pops up on the right side of the ZDE as soon as your script creates any output. Use this to keep an eye on whether your scripts are creating the correct browser code.
Zend provides still other debugging facilities. For example, using remote debugging, you can actually debug your application as it works on the site. This has several advantages in that you can track your application working with input as it would normally. This is often quite hard to do otherwise. Further, the output from the Debug window is displayed in the browser. This all requires Zend Server to be running on the Web server, but we won't go into that here.
With all the debugging and editing functionality provided, we say it once again: Download a demo copy and play around with it. You never know: you might find that this is the answer to your programming dreams. Before we finish our whirlwind tour of Zend's development offering, several other important tools should get a mention.
Zend has also provided developers with a profiler (found within the Tools menu option on the ZDE) to help analyze the performance of their applications. This profiler can be used to determine how to improve an application's performance by identifying problem areas. Several tabs provide you with different types of information, ranging from pie charts showing the amounts of time consumed by scripts, tables, and diagrams displaying statistics for various functions to a call trace to monitor the linear consumption of time from call to call.
Also, Zend can integrate with CVS version control, and you should consult the documentation to see how to get this up and running.
Finally, you can also install the safeguard suite. This gives you the option to electronically license your software. The suite comes in two sections: the Encoder and the License Manager. The encoder simply creates encoded binary files which are then distributed. This helps to prevent intellectual property from being copied or modified. The License Manager creates license keys that allow you to impose the license restriction you want, based on the criteria you supply.
That brings us to the end of the tour of Zend Studio Client and the ZDE. Now we take a look at other development environment offerings.
A trial version of Active State's Komodo can be downloaded at its site: http://www.activestate.com/Products/Komodo/. The professional version, used for commercial purposes, will set you back $295, so it is certainly a good idea to give the demo version a try before buying. Historically, it has been available for both Linux and Windows, but as of the latest release, 2.5, it is now also available on the Solaris platform.
Komodo is an open source development environment, as opposed to being PHP specific, and it supports, among other things, Perl, Python, Tcl, and XSLT. As of this writing, however, the PHP5 debugger extension is not yet available, so debug support in Komodo is restricted to earlier versions. You should consult the Komodo Web site for any updates on this.
Komodo provides you with a Project Manager that can be used to perform a large number of actions. By default, it appears down the left side of the DE window, and project-related functionality can be accessed through the Project main menu item. Among other things, you can:
Create and open projects
Add files and folders
Add commands, templates, URLs, Web services, and dialog boxes
Organize, save, and close projects
Additionally, you can access pop-up context menus, as shown in Figure B-14, by right-clicking the project members.
The context menu you get depends on the type of element you have chosen.
Komodo's code editor has some interesting features, as well as the more standard ones such as coloring and indentation. For example, code folding is provided to collapse sections of code, allowing you to look at abstracted, or skeleton, versions of your code to get an overview of what is happening. Figure B-15 shows the Editor window with collapsed code.
The editor also provides autocomplete functionality for PHP specifically, for classes, functions and variables. Classes in the current and included files are displayed when the word new is typed in, and class methods are displayed when the -> operator is used. Similarly, all user-defined functions and PHP functions will be displayed after four matching characters are typed in.
Another nice feature of the editor is called tips (tips tell you what parameters you can use with a function), which display after you have typed in the opening brace for a given function either user defined, or PHP. Figure B-16 shows the call tip for a user-defined function.
There are plenty of other features in the editor, but most of them are pretty intuitive to use and need not be covered here in any detail. A brief list follows:
Most Recently Used List
Detect Changed Files
Preview in Browser
Background Syntax Checking
We won't look into the debugger in too much detail here because the PHP5 extension has not yet been released. There are some configuration requirements to get Komodo's PHP debugger working, and you should consult the documentation for instructions. Apart from this, Komodo provides you with a full-fledged debugger, which includes:
Viewing the call stack
Adding command-line arguments
Of course, Komodo comes with a host of other tools to supplement their editor and debugger. Let's take a quick look through those here.
Because Komodo allows a host of items to be added to projects, such as shortcuts, folders, files, commands, and templates, it also provides a toolbox in which to store all these for easy access. You can work with the toolbox either through the tab in the left pane (shared with the Project tab), or the Toolbox main menu item. Figure B-17 shows the sample items available in the toolbox. In this case, the snippet was added to the code window simply by double-clicking it.
Komodo can also be integrated with CVS and Perforce (Perforce is SCM, or Software Configuration Management software). To get this up and running, you need to go to the main menu and click Edit Preferences Source Code Control CVS. This will bring up the dialog box shown in Figure B-18 (assuming that you haven't installed CVS yet), and from there you can download CVS if you require, or search for the relevant executable. Notice that the configuration settings for Perforce are directly below those for CVS in the navigation tree.
With that, we leave Komodo and urge you once more to download the demo version to play around with. One caveat in terms of cost here is that you might find that you are paying extra for functionality that is not really useful to you. For example, some tools that come with Komodo are specifically for Perl, such as the Perl Dev Kit. This adds to the development costs of Komodo without providing much value to PHP developers.