Analyzing Code

The PDT includes full PHP code-analysis abilities, error highlighting, hovering, tooltips and other visual aids (see Figure 1).

The code analyzer runs when the PDT is loaded and upon every save of modified code. It analyzes code, highlights errors and warnings detected, highlights the specific code segments that caused the problem and provides explanation and solution hints as hovered tooltips.

Figure 1  PDT: Error Highlighting

Note:  Errors: Code causing an error is marked with yellow underline.
Warnings:
Code causing a warning is marked with red underline.
Warning rectangles - are displayed on the annotation bars.
Tooltip: Hover over warning rectangle to display.
Explanation / example: Place cursor into code, click F2 to display.

Setting Analyzer Preferences

  1. Click Windows | Preferences | PHP | Code Analyzer to open the Code Analyzer preferences dialog.

Figure 2 - Code Analyzer Preferences

  1. Click on each category to open and display members. The category types are:

  1. Set the severity level (ignore or warning) for each member of each category.

  2. Click Apply, then OK to exit. The Analyzer will issue warnings only for categories for which "ignore" has not been selected.

  3. To disable a member of any category - change its severity level to "ignore". The Analyzer will no longer issue warnings for that member regardless of actual error severity.

Problems Pane

The Problems Pane view is located at the bottom center (unless moved by user). It lists errors and warnings issued by the PDT and is synchronized with the Analyzer.

Note: The Problems Pane lists errors and warnings for all files in the Workspace. It lists the file name (Resource), the project name (Path) and the line number (Location) of the code causing the problem.

Example

  1. Generate warnings using the following code:

<? while(print $a) {

echo $a--;

}

if(($a = array(1,2))) {

echo "test";

} ?>

Figure 3  - Warnings

  1. Double click on a warning listed in the Problems Pane. The file containing the code will open in the Editor pane at the code Location causing the error.

Note: No new warnings will be issued in the problem Pane, the Annotation or the Overview bars until you modify and save a code change.