Menu

Error Identifier: postInc.overwritten

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

Why is it reported? #

The post-increment $i++ raises $i by one, but that new value is never read — $i = 5 replaces it before any code looks at $i. The post-increment has no effect on the program. This usually indicates leftover code, or a logic error where the incremented value was meant to be used before the variable is reassigned.

This is different from postInc.unused, where the new value is simply never read. Here another assignment overwrites it first.

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 post-increment if the new value is not needed:

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

Or use the new value before the variable is reassigned:

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

How to ignore this error #

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

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

Rules that report this error #

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