Skip to content

Diagnostics ​

Every diagnostic has a stable code. In .php files, diagnostics are filtered by the PHPStan level of the project (see Configuration); in .sphp files they are always reported.

CodeNameRaised when
SPHP0001syntaxThe file doesn't parse. Other diagnostics of the file are held back until it does.
SPHP0002unknown typeA type name doesn't resolve.
SPHP0003top typemixed, Any or another top type is written in StirPHP code.
SPHP0004missing typeA declaration needs a type and has neither a type nor an initializer.
SPHP0005type mismatchA value isn't assignable where it is used (assignment, argument, return, when exhaustiveness, ...).
SPHP0006undefined variableA name doesn't resolve to a binding, constant or property.
SPHP0007undefined functionA called function doesn't exist.
SPHP0008undefined classA class, interface, enum or record doesn't exist.
SPHP0009undefined memberA property, method, constant or field doesn't exist on the type.
SPHP0010reassign immutableA val, parameter, read-only property or read-only collection is modified.
SPHP0011val/var clashA val x and a var $x share a name in one scope.
SPHP0012nullable accessA member of a nullable value is used without ?->, !! or a null check.
SPHP0013incompatible comparisonTwo values that can never be equal are compared.
SPHP0014argument countToo many or too few arguments, or an unknown named argument.
SPHP0015invalid operandAn operator is applied to a type it doesn't support (. on a Bool, member access on Any!, ...).
SPHP0016sigil mismatchA val is written with $, or a var without it.
SPHP0017undeclared assignmentA variable is assigned without a var declaration.
SPHP0018not callableA value that isn't a function is called.
SPHP0019untyped escapeAn Any! would be returned or stored in a property.
SPHP0020generic arityA generic type is given the wrong number of type arguments.
SPHP0021unnecessary null check?-> or ?: on a value that can't be null (a warning).
SPHP0022return valueA function with a return type can end without returning.
SPHP0023instantiationnew on an interface, abstract or sealed class, enum or record.
SPHP0024visibilityA private or protected member is used from outside.
SPHP0025duplicate declarationA name is declared twice in one scope.
SPHP0026unsupported syntaxPHP syntax that StirPHP doesn't allow in .sphp files.
SPHP0027varianceAn in/out type parameter is used in the wrong position.
SPHP0028type boundA type argument doesn't satisfy its parameter's of bound.
SPHP0029not inlinableAn extension function uses something it can't (private members, recursion, local state of the caller).
SPHP0030missing implementationA class doesn't implement an abstract member.
SPHP0031incompatible overrideAn override doesn't match what it overrides, or overrides something final.
SPHP0032data classA data class breaks its rules (for example a mutable property).
SPHP0033redundant conversionA conversion does nothing: as String on a String, intval() of an Int, or strval() of what ., echo or a template converts anyway (a warning).
SPHP0050PHPDoc mismatchA PHPDoc type contradicts the native type it annotates (.php files).

Silencing a diagnostic ​

For a false positive, a comment silences every diagnostic on a line:

sphp
// @sphp-ignore-next-line
val a: String = 1
val b: String = 2 // @sphp-ignore

Alone on its line, @sphp-ignore applies to the next line; after code, to its own. @sphp-ignore-next-line and @sphp-ignore-line say which explicitly. A code written after the comment doesn't narrow it down.

In .php files the comments are PHPStan's: @phpstan-ignore, @phpstan-ignore-next-line and @phpstan-ignore-line.

Machine-readable output ​

sphp check --format json prints the diagnostics as a JSON array; see Command line.

StirPHP is open source under the MIT license.