Error Identifier: postDec.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);
date('j. n. Y')--;
Why is it reported? #
The post-decrement operator (--) can only be applied to variables, properties, array offsets, or static properties. Applying it to a non-variable expression such as a function call result is not valid because PHP cannot assign the decremented value back to anything.
In the example above, date('j. n. Y') returns a temporary string value that has no storage location, so the -- operator cannot decrement it.
How to fix it #
Store the value in a variable first, then apply the decrement operator to that variable:
<?php declare(strict_types = 1);
-date('j. n. Y')--;
+$date = date('j. n. Y');
+$date--;
How to ignore this error #
You can use the identifier postDec.expr to ignore this error using a comment:
// @phpstan-ignore postDec.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: postDec.expr
Rules that report this error #
- PHPStan\Rules\Operators\InvalidIncDecOperationRule [1]