Menu

← Back to postInc.*

Error Identifier: postInc.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 increment(): void
{
	getCounter()++;
}

Why is it reported? #

The ++ operator can only be used on variables, array offsets, and property accesses. Using it on the result of a function call or any other non-variable expression is not valid because the increment operator needs a storage location to write the new value back to.

How to fix it #

Assign the value to a variable first, then increment it:

 <?php declare(strict_types = 1);
 
 function increment(): void
 {
-	getCounter()++;
+	$counter = getCounter();
+	$counter++;
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Operators\InvalidIncDecOperationRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.