Menu

Error Identifier: postInc.unused

← Back to postInc.*

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 = 0;
	echo $i;
	$i++;
}

Why is it reported? #

The post-increment $i++ raises $i by one, but that new value is never read afterwards. Incrementing a variable whose result nobody observes has no effect on the program. This usually indicates leftover code or a logic error where the incremented 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 increment if the new value is not needed:

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

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

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

How to ignore this error #

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

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

Rules that report this error #

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