Menu
Error Identifier: preDec.expr
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
function doFoo(): int
{
return 5;
}
--doFoo();
Why is it reported? #
The decrement operator (--) is applied to an expression that is not a variable. The -- operator requires an assignable expression (a variable, array element, or property). In the example above, doFoo() is a function call result, which cannot be decremented.
How to fix it #
Apply the operator to a variable instead:
<?php declare(strict_types = 1);
---doFoo();
+$value = doFoo();
+--$value;
How to ignore this error #
You can use the identifier preDec.expr to ignore this error using a comment:
// @phpstan-ignore preDec.expr
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: preDec.expr
Rules that report this error #
- PHPStan\Rules\Operators\InvalidIncDecOperationRule [1]