NetBeans IDE for PHP Editor: Brief Overview
This document is a brief overview of the main features of the NetBeans IDE PHP Editor.
To follow this tutorial, you need the following software and resources.
To successfully develop and deploy PHP applications in the NetBeans IDE for PHP, you need to have all the required software installed and configured for PHP development.
The editor contains the following windows:
You can also open a Navigator window in the left-hand panel by pressing Ctrl + 7. The Navigator shows the structure of a PHP class if the class is open in the Editor. Non-class PHP files are not shown in the Navigator window.
To open help for one of these windows, select any element in the window and press F1.
The following syntax elements are highlighted in the current version:
To change the settings for highlighting, choose Tools > Options and switch to the Fonts&Colors tab. Specify the settings of your choice.
The Navigator window displays code structures as elements of a list that shows the PHP structures of the currently active file. If the file contains any other text sources (for example, HTML) the list displays their structures too. By double-clicking a function or a variable in the list, the cursor points at the declaration of the clicked element.
Caution: The Navigator window only shows PHP code for PHP classes. It cannot show PHP code outside of a class.
The Navigator list does not normally contain any embedded lists, but for complex statements it may contain embedded structures. For example, a PHP class declaration statement can be presented as a tree of declared class members.
The list is dynamically updated while the user types the code.
The Navigator window is shown in the bottom of the left-hand panel.
The editor enables the user to selectively hide and display modules, classes or functions of the currently edited file with PHP source code. To fold or display a piece of code, click the - or + icon to the left of the code, or press Ctrl+ or Ctrl-.
The editor automatically formats the code while the user is typing.
To format a piece of code to make it more understandable, perform the following steps:
The editor automatically adds and removes matching brackets and quotes while the user is typing the code.
You can rename an element such as a class name across all files in a project. The feature forces you to preview your changes before you can make them. The preview window shows you every location of the element and lets you exclude individual occurrences of the element from being renamed.
Rename Refactoring is contrasted with the older feature, Instant Rename. Instant Rename is still available, but it only works in "non-public" contexts, such as renaming a variable inside a method, or renaming private variables and fields. Instant Rename lets you only rename an element within a file and does not provide a preview window.
To use Instant Rename, place the cursor on a name you want to change and press Ctrl-R. If Instant Rename applies to that variable, all instances of that variable or function name are highlighted.
Change one instance of the name and all other instances in the file are changed simultaneously
To use Rename Refactoring, select the element you want to rename and either press Ctrl-R or right-click and select Refactor > Rename. A dialog opens for you to rename the element.
Rename the element and press Preview. The Refactoring window opens. In this window, you can find every instance of the element in your project and decide whether or not to rename it.
For more information about Rename Refactoring, see the screencast Rename Refactoring and Other Editor Improvements in NetBeans IDE for PHP.
Code Completion is a common name for a set of features that speed up the process of coding.
The following types of code completion are distinguished:
Snippets enable the user to generate code for various elements automatically.
The editor provides context-sensitive proposals for completing any number of starting symbols of:
The editor not only suggests expansions but also provides parameter hints. To apply Code Completion:
In the current context, the term ""abbreviations" refers to a set of predefined character strings that correspond to the key words used in a programming language. Each abbreviation is associated with an expanded text which contains the full key word and a code template for the key word with parameter hints. To apply this functionality, type an abbreviation and press Tab.
The abbreviation is replaced with the corresponding key word and the code template for the key word is provided.
To view the list of defined abbreviation with code templates:
For more information, please see Code Templates in NetBeans IDE for PHP.
After the new keyword, the code completion window is displayed with constructors and parameters for all available classes in the project.
SQL code completion displays when a string begins with the SQL keyword "select." The first step is to select the database connection.
All database connections registered with the IDE are displayed.
After you select the connection, SQL code completion offers all tables from that database connection.
If the table has columns, those are displayed as well.
SQL code completion also works with table aliases.
Code completion supports fully qualified, partially qualified, and unqualified namespace names from PHP 5.3. For more information, please see our screencast.
Code completion between class members offers to override or implement methods.
Starting in NetBeans IDE 7.1, code completion for catch statements includes only classes that inherit from Exception.
NetBeans IDE 7.1 for PHP introduces the Rectangular Selection action. This editing function is useful in cases such as deleting line numbers in pasted code.
To enable rectangular selection, press the Rectangular Selection toggle button or Ctrl-Shift-R.
When Rectangular Selection is enabled, you can make the selection with mouse or keyboard. When you use the keyboard, place the caret on a corner, keep SHIFT pressed down, and select what you need with the arrows keys.
f you write text while an area is selected, the text is placed on every line in the selected area. This can be useful, for example, for simultaneously changing the access modifiers of multiple fields in a class.
Built-in support for PHPDocumentor was added in NetBeans IDE 7.0. For more information, see the screencast Generating PHP Documentation With NetBeans IDE.
Warning: PHPDocumentor does not fully support PHP 5.3. Namespaces and some other 5.3 features are not documented by PHP Documentor.
When you press the combination Alt-Insert (Ctrl-I on Mac), a menu opens with all possible code generators. The list of generators is context sensitive. It depends on the position of the caret in the code when the key combination is pressed. Depending on your position in the code, you can generate a database connection, database tables, lorum ipsum text, and several others. This section describes only the following code generators:
You can generate constructors by pressing Alt-Insert (Ctrl-I on Mac) when the caret is inside a class body, but not inside any functions contained in that body. When you select Generate... Constructor, a dialog opens llisting the fields you can initialize by the constructor. The field names are used as parameters of the constructor.
You can decide not to select any fields. In this case, the IDE generates an empty constructor, with no parameters. If the field is a class with properties, you can either select individual properties, or you can select the class, in which case all the class' properties are selected automatically.
For more information, see the NetBeans PHP blog post.
You can generate getters and setters by pressing Alt-Insert (Ctrl-I on Mac) when the caret is inside a class body and selecting Getter, Setter, or Getters and Setters. Only the possible functions are displayed. For example, if you already have setters for the available properties, only the getter option appears.
When you select Generate... Getter/Setter/Getter and Setter, a dialog appears with the properties for which you can generate a getter or setter. The properties are displayed in a tree. If you select a parent class, you automatically select all that class' properties.
You can name a getter or setter according to either the convention getName or the convention get_name.
You can generate overridden or implemented methods by pressing Alt-Insert (Ctrl-I on Mac) when the caret is inside a class declaration and there are multiple class members. A dialog opens showing the methods you can insert and indicating whether they are overridden or implemented.
This feature complements the "Implement all abstract methods" hint and code completion for overridden and implemented methods.
For more information, see the NetBeans PHP blog post.
The editor prompts the user regarding the formal parameters of a function or a method in the context where the function or method is called.
You can define a variable and its type in a comment. The comment has to be in the format /* @var $variable type */ . If the comment is written correctly, the var tag is in bold font.
You can use the code template vdoc, followed by Tab, to generate a comment that defines a variable. The variable name is selected, and you can change it. Then press Tab again, and the type is selected.
The code template automatically sets the variable name and type. If a variable is used after the place where you insert the template, then that following variable name is suggested by default. If there is not any variable used after the place where you insert the template, but there is a variable used above the template, then that preceeding variable name is suggested as default. If NetBeans IDE is not able locate any variable near where you use the template, then the default name is variable. The variable type is set automatically according to the same rules.
The editor analyzes the syntax of the code while you type, and marks syntax errors by underlining the erroneous lines and setting a red bullet next to them. To get an explanation of the error, mouse over the erroneous line or click the red bullet. A tooltip appears with a short explanation of the error.
NetBeans IDE for PHP supports PHPUnit automated tests, including code coverage. Starting in NetBeans IDE 7.1, you can use test groups in your code.
NetBeans IDE also supports the Selenium portable test framework, in combination with PHPUnit. A Selenium plug-in is available from the Update Center. Installing this plugin adds a Selenium server to the IDE's registered servers and adds Selenium test options to the PHP menus.
See Testing with PHPUnit and Selenium for more information.
A spellchecker is available. In the Options dialog, you can switch spellchecking on or off for different languages.
In the Options dialog, you can add and remove new dictionaries and set the locale. When you want to add a new dictionary, you have to have a file with the words. The format of the dictionary file is a list of words with every word on a new line. You have to tell NetBeans the encoding of the dictionary file and for which locale the file should be used.
When the spellchecker finds a word that is not in its dictionary, it underlines that word in red. The spellchecker also adds a tooltip to that word that says "Misspelled word." Note that HTML text is checked in PHP files.
Symfony framework support and Zend framework support are built-in to the PHP editor. It recognizes existing Symfony and Zend frameworks, and you can add the framework to new projects in the last panel of the new PHP project wizard.
In a PHP project with Symfony or Zend support, you can run Symfony or Zend commands from the project's context menu.
Use the UI for the commands to:
The list of commands is project specific. This means that if one uses e.g. Doctrine instead of Propel, no Propel commands are listed, just the Doctrine ones. Also, all the commands from the project's Symfony plugins are available.
Code completion includes Symfony variables in Symfony views and Zend variables in Zend views.
The IDE also provides navigation shortcuts between Symfony or Zend views and actions. These shortcuts were improved in NetBeans 6.9. In addition, code completion in view templates/files now includes variables that are declared in controller/action files. See the NetBeans PHP blog post for details.
For more about our Symfony framework support, please see the Symfony screencast.
For more about our Zend framework support, please see the Zend screencast.
NetBeans IDE 7.1 includes a plugin for Smarty framework support. This support includes basic Smarty 3 features, namely Smarty 3 code completion and delimiters.
Toggle between Smarty 3 and Smarty 2 behavior in the Options window. Go to Tools > Options (NetBeans Preferences on MacOS), select PHP, and open the Smarty tab. The Smarty framework plugin must be installed.
To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans IDE PHP development features, join the mailing list.