Using PHPLint with NetBeans
Last updated: 2016-01-25
NetBeans is a powerful multi-platform IDE originally born to write Java programs, but it also
supports several other languages though specialized plug-ins, and PHP is among
these.
NetBeans main window on Linux (click to enlarge).
The image above shows the PHPLint project opened in the main window of NetBeans
with the PHP plug-in enabled. This plug-in parses all the sources from the opened
project and collects all the informations about the defined items: constants,
variables, functions and classes will be at your fingertips!
And it is very smart, as it parses all the DocBlocks and does a deep flow
analysis on the source, so it knows exactly which type a variable really is
and may suggest what you can do with it.
Tips and tricks with NetBeans
And here is a list the tips and tricks I use with NetBeans:
-
Select the PHP version 5.6 or higher and UTF-8 source encoding.
From File → Project properties → Source select the PHP version
your sources will be compatible with, so that NetBeans will check the
syntax accordingly.
Project properties dialog box, Sources (click to enlarge).
-
Exclude the modules folder. In the File → Project properties →
Ignored Folders add the modules' directory: the PHP files it contains are
not actual PHP code, and may make the suggestions quite confusing with
duplicated entries.
-
Keep the formatting of your sources uniform and consistent.
Under File → Project properties → Source you may choose between
global and project specific formatting options. The globals options are
set from the Tools → Options → Formatting menu.
I always choose "globals" too keep the formatting of all my sources uniform
and consistent:
Formatting options (click to enlarge).
Smart guys always use tabs: choose the number of spaces per each indentation
(used by the formatting tool) which normally must match the number of spaces
per tab (applied when you press the tab key). Do not forget to also select
"PHP" from the menu then check "Use All Languages Settings" to inherit these
setting from the global ones.
-
Keeps DocBlocks updated.
It is very important to keep your DocBlock in synch with the actual source
because NetBeans parses them and uses the informations it collects to
perform static analysis on the source and give you the correct suggestions.
The fastest way to add a DocBlock to a function or method is to set the
cursor just before the function keyword and type /**
then press enter: NetBeans will magically create the skeleton of the DocBlock,
sometimes also guessing the correct types of the parameters and return
type for you. Here is a simple example of DocBlock:
/**
* @param Person[int] $persons
* @return void
*/
function showNames($persons) { ... }
Note that NetBeans recognizes the array syntax Person[int]
so it knows that $persons[$i]-> is an object of type Person
and may suggest the corresponding class members while you are typing.
-
Give the right name to things. Click on any constant, variable,
function, parameter, class or property, either in the source or in a
DocBlock and type control-R to "refactor": NetBeans will rename any
occurrence of that item in the sources and DocBlocks. But beware:
this task can only be performed with success if the source has already
been well documented with proper and updated DocBlocks.
-
Direct access to the PHP manual.
Click anywhere inside the name of a function name, class name or method
name, then click on the PHP icon in the tools bar to open the corresponding
manual page in your preferred browser as set in File → Project properties →
Browser.
-
Spell checking of the comments.
Unfortunately, spell-checking un PHP sources is performed only on the text
portion of the source, not inside the source itself. But there is a simple
trick: add a space inside the <?php tag so that it reads
< ?php; in this way, all the source becomes bare text an gets
checked, including comments and DocBlocks.
Alt-Return on a bad word for suggestions and options.
Add missing words to your private dictionary.
-
Install the QuickOpener plug-in. These icons are from that plug-in:
Icons set by the QuickOpener plug-in.
which respectively: 1. Open a terminal window on the same directory
of the currently selected folder or source. 2. Opens the file manager on the
currently selected folder or folder containing the current source file.
3. Copy the path of the current folder or source, you may then paste in the
embedded terminal window with Ctrl-Shift-V.
4. My preferred: launches an
arbitrary command with the path of the current folder or source as parameter;
here you may define the call to phplint.tcl, which is a very useful companion
of NetBeans:
QuickOpener custom commands (click to enlarge).
- Try the Help menu for more about NetBeans.
References
Still no comments to this page. Use the Comments link above to add your contribute.