REVIEWS Studio 4

Exploring the Zend Studio 4 developer environment RAPID DEVELOPMENT

PHP experts consider Zend Studio the most mature and feature-rich IDE for PHP. The latest version offers enhanced database manip- ulation and other improvements. We’ll put the Zend Studio IDE through its paces and show you how you can use it to speed up PHP development.

BY CARSTEN MÖHRKE

he choice of an integrated devel- opment environment is often a Tmatter of taste. Many PHP devel- opers prefer text editors like or . Developers who favor a more inte- grated approach have several choices in the Linux world. The free Quanta Plus IDE, the closed source Maguma environ- ment, and even (with the right Zend Studio has set of plug-ins) are all genuine alterna- the reputation of being tives to an editor. For PHP developers, one of the most mature and pow- erful IDEs. version that disables so many useful Zend Studio Personal Edition Zend Studio is the brainchild of Isra- features it is not really worth the effort The following features are not available el’s Zend Software, a vendor that prefers (see the box titled “Zend Studio Personal in Zend Studio Personal Edition: to be known as “The PHP Company.” Edition”). Older versions often suffered from per- • Profiler Installation • Code Analyzer formance problems or instability, but the • CVS support latest version, Zend Studio 4, is an After downloading and unpacking the extremely powerful and stable developer 47MByte archive, you can launch the • Inspectors environment. Zend Studio is neither installation program directly. A wizard • FTP support Open Source, nor is it free of charge, prompts you for a few required details. • Remote Debugging although US$ 249 is a fair asking price. Besides the typical questions concerning • Function descriptions in code comple- You can download a trial version from directories, you can say which PHP ver- tion the Zend website. The test version is sion you want Zend to support (4 or 5). • File searching full-featured for the 21 day trial period PHP 4 and 5 are not one hundred per- • Printing and then degrades to the “Zend Studio cent compatible and have different com- • Block indenting Personal Edition,” a non-commercial mand sets, so this selection will influ-

42 ISSUE 57 AUGUST 2005 WWW.LINUX - MAGAZINE.COM Advertisment

Figure 1: An installation wizard walks you through the Zend Studio installation process. Make sure you install the Zend Studio Server. ence syntax highlighting and shows files, servers, and checking. The good news is databases for direct access. that you can change your Below this are various inspec- mind later. Another impor- tors that give developers a tant part of the installation is quick overview of the files, deciding whether to install classes, and methods belong- Zend Studio Server (Figure ing to the current project. The 1.) Say yes, because you will lower part of the screen is need the server for effective reserved for messages and debugging later. the debugging window. The second window gives you Interface information on variable val- After completing the installa- ues, the call stack, and simi- tion, Zend Studio automati- lar things. On the right is a cally detects your system’s display area that gives you language settings and the “screen output.” This launches with the correct lan- area provides an at-a-glance guage support. At this time of overview of the output the writing, the environment script generates. Zend Studio supports English, French, also displays the HTTP head- German, Russian and Span- ers; this is a useful feature, ish. and one that a browser would The user interface (Figure not give you. Finally, the edit- 2) is divided into a number of ing window is at the center of panels. The top left area the screen. Good news for

Figure 2: The Zend Studio user interface. REVIEWS Zend Studio 4

those of you worrying where to put all when you launch the IDE, and this can one of the most useful tools. While you those panels on a small screen: you can be really annoying if you have a long list are typing, Zend Studio shows a list of scale panels and hide any you do not of servers, or if connections are down. functions, variables, or other items that need. Zend Studio also has CVS support, start with the letters you have typed. which you can again configure through Considering the number of PHP com- Settings the tools menu. mands, the fact that the system gives a Before you start using Zend Studio for short overview of what each function production, you will probably need to Setting up a Database actually does is very useful. A parameter tweak a few settings. The dialog box for Server list appears when a function has been personalizing the system is titled Prefer- Direct access to database servers is a uniquely identified. ences and is launched by selecting Prefer- new feature in Zend Studio 4. Clicking Zend Studio dynamically adds any ences in the tools menu. on SQL in the file management window functions, variables, and classes you Many of these settings are a matter of (top left) displays a list of configured define to the code completion list. This personal preference. However, there are servers. Of course, the list will be empty is not restricted to the file you are cur- a few additional options that you will if you have just finished installing the rently editing, but also includes any need to change to give you a useful program. To populate the list, right click other files you have open at the same developer environment. For example, in the window and select “Add Server” time. (The code completion feature can you can define how to display the tabu- to open the window shown in Figure 4. lead to confusion when Zend offers you lator in the Editing tab. The Newline Currently, Zend Studio supports direct a class from an open file that is not part format can also be important; this set- access to the following database servers: of your current project.) ting specifies whether a newline is Oracle, SQLite, Microsoft SQL Server, As PHP does not support variable type represented by a carriage return and line PostgreSQL, and MySQL. After entering declarations, Zend Studio has no way of feed (Windows standard) or just by a your access credentials, you can immedi- knowing what data type a parameter you line feed (Unix standard). ately access the server. Right clicking pass to a function should represent. opens a connection and gives the devel- However, developers can add documen- Configuring the Server oper environment access to any data- tation blocks (docblocks) to provide this In many cases, you will need to work on bases, tables, and records for which the information for their own functions, files stored on a server. The Zend IDE current user has permissions. classes, and methods. To do so, right gives you the ability to store files directly Developers can view the table struc- click on a function in the Project Inspec- on the server using an FTP connection. ture or content in the window normally tor and select Add description to insert You can use SFTP or FTP over SSH for occupied by the editor. Zend Studio does an empty docblock. more security if necessary. The file menu not support direct record manipulation, The first line should be a short takes you to the dialog where you can however, as it does not claim to be a description of the function, which will set up a new server connection (Figure database front-end. In database mode, also appear in the code completion help. 3.) To set up a connection, you need to you can use the lower part of the inter- Docblocks are tag extensible, allowing supply the usual information, such as face to enter SQL commands (Figure 5). them to describe the properties of a the host and user names and a pass- This feature allows developers to verify function or class. Tags always start with word. Make sure you uncheck the Recon- SQL queries before adding them to the @. A tag needs to be preceded with an nect on Startup option or Zend Studio PHP codebase. asterisk (*) and a blank. For example, an will attempt to connect to the server entry such as @return: would describe Production the return type for the function. The Although Zend Studio does allow you to @param: tag refers to a parameter. You edit individual files, developers will need a separate entry for each parame- more typically want to work on projects. When you add a new project by select- ing New Project in the Project menu, a wizard pops up to prompt you for the project name, the path for storing the project files, and the debugging prefer- ences for the project. After you create a project, the new project is displayed on the left in the Project Inspector area. You can now right click or use the File menu to add files to the project. Zend Studio has several useful fea- tures to support encoding work. Besides Figure 3: The Configure FTP Server dialog syntax highlighting, which even the box lets you set up a connection to an FTP most simple of editors now support, server. automatic code completion is probably Figure 4: Configuring an SQL server.

44 ISSUE 57 AUGUST 2005 WWW.LINUX - MAGAZINE.COM Zend Studio 4 REVIEWS

sequence [Ctrl]+[Alt]+[A] or by accessing the analyzer through the tools menu. Debugging Of course, Zend Studio helps developers locate more hidden errors. The debug- ging tool allows you to interrupt code execution and check what is happening to critical variables. Zend Studio sup- ports both local and remote debugging. Local debugging means running your code directly in Zend Studio with the output appearing on the right hand side of the Zend Studio window. As it is often impossible to test everything locally, Zend Studio also supports debugging on a server. Just running the whole program code and checking the results is not a useful way of debugging. This is why Zend Figure 5: Accessing a MySQL server. Studio allows you to set any number of breakpoints. You can add or remove a ter, followed by the variable name and your mistakes as you can. Again, Zend breakpoint simply by clicking the line the data type. You’ll find a complete list Studio gives you a wide range of options. number. After setting breakpoints, press- of tags at [1]. The code analyzer is a neat feature. ing [F5] or selecting Run in the debug This approach may seem a little com- Although other IDEs have code analyz- menu will run the code. When the parser plex at first, but it makes sense, as doc- ers, Zend’s analyzer works in a unique reaches a line with a breakpoint, it inter- blocks can be really handy when it way. The analyzer helps you find irregu- rupts the program execution just before comes to automatically generating pro- larities, which may or may not be errors. that line, allowing the developer to gram documentation. To help you with It analyzes your code and lets you know inspect the system status more closely. this chore, Zend Studio has the PHPDoc- if it thinks it has found a mistake. As previously mentioned, the right- umentor below the Tools menu (Figure The code analyzer will pick up lines hand part of the screen displays the 6.) The documentor creates HTML, PDF, that may be syntactically correct but are script output. You can inspect the cur- CHM, or XML formatted documentation poor programming style. You can call the rent script status below this area. This for a source code file. code analyzer either by pressing the panel shows you the current variables, Automatic syntax analysis is another useful feature. Zend Studio automati- cally checks your input for syntax errors while you are typing. If it discovers an issue, it underlines the line of code in red, and it places a red stroke in the right-hand margin to mark the spot. You can then hover your mouse over the stroke, or the faulty code, and the IDE will show you the error message. Zend Studio also provides code snip- pets – external code fragments provided by the open source community that have been tested for functionality. These code snippets are another very useful addition to Zend Studio 4 that can help you avoid re-inventing the wheel. The library has over 300 snippets and also supports an update function that allows you to import more snippets. Of course, nobody can write code without making mistakes; it’s just important to be able to find as many of Figure 6: The PHPDocumentor assists with creating documentation for the source code file.

WWW.LINUX - MAGAZINE.COM ISSUE 57 AUGUST 2005 45 REVIEWS Zend Studio 4

Studio. You can enable server-supported debugging in Preferences | Tools | Debug. After doing so, it makes sense to test the connection to the server by selecting Check debug server connection. After successfully completing the test, you can then use the Debug URL function, or press the [F8] shortcut key. Type the URL of the page you want to test in the window that then opens. Click on OK to launch the session; this opens the browser and allows you to remotely con- trol the session. Zend Studio retrieves the source code directly from the server, so there is no need to create a local copy. In contrast to local debugging, the remote debugger halts before the first line of code, remov- ing the need to set a breakpoint. Apart from that, the functionality is just like a local debug session. Interestingly, output Figure 7: The Zend Studio Profiler analyzes CPU usage and helps you locate bottlenecks. is shown in Zend Studio and in the browser. including both the data type and current sion is remotely controlled by Zend Stu- In some cases, output is first stored in content. Objects or array contents are dio. To support remote debugging, you an output buffer and not sent to the displayed in the same way. By default, need to install the Zend Studio Server, browser. In that case, adding flush() to you only get to see local variables (that which is included with the IDE license. If the source code will send the output is, variables visible in the current con- you did not install the server component buffer content to the browser. text.) However, you can click on the + while installing Zend Studio, you can sign next to GLOBALS to view superglo- download the server from www. zend. More Power bals, including their current content. The com. You may be familiar with the issue of call stack also makes for interesting The server is not a stand-alone appli- slow response from new web applica- viewing; you need to click on Stack to cation but needs to be integrated with an tions. It is often difficult to locate the display it. The call stack is where the existing Apache Web server. You can use source of the bottleneck. Zend Studio parser manages function calls. This either the Apache server included with gives you a profiler in the Tools menu. allows you to view the stack with the the product, or an Apache server you The profiler analyzes the program run- names of the functions the system has have installed previously. In the latter ning on the debug server and displays called at the current time. The function case, the installation program will the CPU time required to process a file or at the bottom of the stack will always be attempt to locate the paths to the config- function (Figure 7.) main(), that is, the body of the program. uration files, such as httpd.conf and . This view gives developers the advan- ini, or prompt the user for the paths. Conclusions tage of being able to inspect the vari- Additionally, the installation program Although there are cheaper ways of pro- ables in functions lower down the stack, needs to know which clients are allowed gramming in PHP, neither Eclipse, nor which may be overwritten by other calls. access to the server. The Emacs, nor Quanta+, give you a debug- should not be deployed on production ger. Zend’s context-sensitive help is Remote Debugging Web servers, as the installation routine much more mature than the alternatives. After reaching a breakpoint, you can replaces the index file in the server’s Developers working on larger projects either step through the code line by line DocumentRoot directory. Now, after might miss support for Subversion, and or run the program to the next break- relaunching the server, whenever you the CVS client is still not perfect, but point. The former approach is useful if call the server’s homepage in your Zend Studio 4 comes with more than you want to inspect the changes to indi- browser, you are automatically redi- enough good features to compensate. vidual values as the code progresses. rected to the Zend Studio Server page. When all’s said and done, Zend Studio Pressing [F11] in the debug menu tells The page gives you an overview of the is well worth the asking price. ■ the interpreter to parse the next line. configuration and allows you to modify Selecting Run tells the interpreter to run the PHP configuration. The installation INFO the code to the next breakpoint. program creates backup copies of the [1] PHPDocumentor manual: http:// www. Remote debugging is a more advanced modified files. . org form of troubleshooting where the code The really interesting features for con- [2] Zend: http:// www. zend. com runs directly on the server and the ses- trolling the Zend Server are part of Zend

46 ISSUE 57 AUGUST 2005 WWW.LINUX - MAGAZINE.COM