PHP Design became object-oriented with the release of PHP version 5.0, which resulted in the need for new PHP tools, for example, the ability to visually browse through PHP classes, PHP functions and other PHP objects. This tutorial explains how to use advanced PHP design functionality that is available in NuSphere PhpED’s Code Explorer for visually representing the hierarchy of PHP objects. To follow along with this tutorial, simply download a free trial of the NuSphere PhpED integrated development environment for PHP (PHP IDE).
How to Design a PHP application in the Code Explorer
The PHP code explorer tab is located on the left-hand side of the PhpED XML IDE. When a PHP file is loaded in the PHP Editor, the Code Explorer displays a complete hierarchy of PHP classes, PHP functions, PHP variables and PHP Constants in a tree; each type of PHP object is visually represented by its own symbol. There are four different PHP design modes to choose from:
- PHP Class View. In this mode PHP design objects are grouped by types (for example, constants, variables, classes and functions). This provides a general overview of your project and is probably the most widely used for your average PHP application designer.
- ChangePHP Project list. Lists out all of the .php files in the current project, grouped by file type. If you click on a file, an explorer-style view of the classes and functions available from that PHP file will open, including the expected arguments for each. Project List view provides the most comprehensive information for the design of a PHP application.
- PHP Project Tree. Displays the project structure with folders, files and file content, grouped by type. If you click on a file, an explorer-style view of the classes and functions available from that file will open, including the expected arguments for each.
- Single PHP file. In this mode, the Code explorer only displays the contents of the active PHP.
You can use the context menu to switch between these modes by right-clicking on the Code Explorer area. For example, the following illustration displays a PHP File in Class View in the NuSphere PHP Designer.
Using the PHP Code Explorer to Simplify PHP Design
PhpED's Code Explorer allows you to easily navigate between different PHP Classes, PHP Functions etc. To navigate to specific PHP Class definition, PHP function, PHP variable or PHP Constant you should:
- Double click on the definition of the PHP class, PHP function or PHP variable in Code Explorer tree or
- Select the PHP Class definition, PHP function, PHP variable or PHP Constant in Code Explorer tree; then from the short-cut menu, select "Go to Definition", as illustrated in the following illustration:
- If the selected element is a PHP variable, the cursor display will provide insight into where the variable is used and/or defined. If the design of a PHP application involves the same variable used in more than one PHP File or in multiple locations in the same PHP File, the PHP Designer can navigate between different instances of the same PHP variables by repeatedly clicking on that variable. For example, the illustration below shows the occurrences of PHP Variable $dbInst. This particular design has three files, of which one is shown in the following illustration:
Searching Using the Code Explorer
If you design a complex PHP application containing a large number of classes, functions and variables, finding what you need can be challenging. The search feature of Code Explorer lets you search by name for the elements used in your PHP Design:
- Enter the name of PHP Class definition, PHP function, PHP variable or PHP Constant in the search input form on the top of PHP Explorer
- Press on the Search button (the binocular icon).
- Code explorer will expand the tree at the location of the item that you were looking for
- To find the next occurrence of the search term, simply continue pressing the Search button
For example, the following illustration shows the search functionality at work:
Download PHP Designer
In this tutorial you learned that you really don't need to memorize all of the different class libraries available to PHP Designers – instead, you can simply use a PHP Code Explorer to navigate PHP classes and functions to simplify PHP design, particularly when working with larger PHP applications. Readers seeking to simplify PHP design can download a free trial of NuSphere PhpED, the product used in this tutorial.