Code Validation

The code is analysed semantically in order to find errors that will be thrown in run time. The editor performs type analysis in linear time on a background thread, not blocking user's UI.

The editor makes use of PHP 5 and PHP 7 type hints and PHPDoc comments. Without specifying the type information the editor analyses values and expressions in order to estimate the resulting type.

Code Structure

Function Arguments Missmatch

  • passed arguments type mismatch with the function parameters definition specified in PHPDoc or PHP type hints
  • mandatory arguments missing

Return Value Missmatch

  • PHPDoc, PHP7 return type hint and actual returned values types mismatch
  • PHPDoc or PHP7 return type hint specifies a return type but some code path does not return any value

Array Access Missmatch

  • accessing scalar value as array
  • accessing object not implementing ArrayAccess interface as array

Unreachable Code

  • a code path is unreachable
  • a conditional code path will be unreachable because the condition is always false

Duplicit Switch Cases

  • duplicit cases are reported as warnings

Unknown Symbols

Unknown symbol name such as a class name, function name, constant name or a namespace name is reported as warning in user's code. These errors usually indicate a typo or missing use or invalid missing namespace name in PHPDoc comment.

Unknown Types

PHP Tools recognize unknown types and provide suggestions that add use declarations or proper fully qualified names for types that are found in the project but are not properly referenced. For more information about suggestions see the documentation page. An unknown type is reported as a warning in the code, an example is in the following image.

Unknown types

Unknown types are recognized in the following situations:

  • An unknown base class.
  • An unknown interface.
    • Aside from the unknown type, PHP Tools verify that the implemented type is an interface.
  • An unknown trait used in a class.
  • An unknown type hint used for a function or method parameter.
  • An unknown type used as function or method return type.
  • An unknown type used in a catch declaration.
  • An unknown type used in a PHPDoc.

Unknown Functions

PHP Tools recognize unknown functions and methods and report their use as a warning in the code. Unknown functions are reportedin the following situations.

  • An unknwon (global) function is called.
  • An unknown method is called.
  • An unknwon static method is called.

Illegal Constructs

Following errors are syntactically valid but will fail fatally once containing file will be executed.

  • Implemented type is not an interface

    • A class is trying to implement a type that is not an interface.
    • A class can implement only interfaces. A single class can be declared as a base class and traits are added by use declarations.
  • Base class is final.

    • The base class is declared as final, which means that is cannot be used as a base class.
  • Using parent without a base class.

No base class

The following example shows an incorrect class hierarchy as it is reported by PHP Tools.

Invalid hierarchy

PHPDoc Keyword Type

  • a keyword in PHPDoc does not exist and is similar to something that does