Menu

Error Identifier: preDec.unused

← Back to preDec.*

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(): void
{
	$i = 10;
	echo $i;
	--$i;
}

Why is it reported? #

The pre-decrement --$i lowers $i by one, but that new value is never read afterwards. Decrementing a variable whose result nobody observes has no effect on the program. This usually indicates leftover code or a logic error where the decremented value was meant to be used.

This rule is part of PHPStan’s dead code analysis. It is reported at rule level 4 and above, and is currently part of Bleeding Edge.

How to fix it #

Remove the decrement if the new value is not needed:

 function doFoo(): void
 {
 	$i = 10;
 	echo $i;
-	--$i;
 }

Or use the decremented value if it was intended to be read:

 function doFoo(): void
 {
 	$i = 10;
 	echo $i;
 	--$i;
+	echo $i;
 }

How to ignore this error #

You can use the identifier preDec.unused to ignore this error using a comment:

// @phpstan-ignore preDec.unused
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.unused

Rules that report this error #

  • PHPStan\Rules\DeadCode\UnusedVariableRule [1]
Theme
A
© 2026 PHPStan s.r.o.