Menu

← Back to preInc.*

Error Identifier: preInc.type

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(stdClass $obj): void
{
	++$obj;
}

Why is it reported? #

The pre-increment operator ++ cannot be used on certain types such as objects (other than SimpleXMLElement), arrays, or resources. PHPStan reports this error when the operand type does not support the increment operation.

How to fix it #

Use a supported numeric type, or perform the operation through a method or explicit arithmetic:

 <?php declare(strict_types = 1);
 
-function doFoo(stdClass $obj): void
+function doFoo(int $counter): void
 {
-	++$obj;
+	++$counter;
 }

How to ignore this error #

You can use the identifier preInc.type to ignore this error using a comment:

// @phpstan-ignore preInc.type
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: preInc.type

Rules that report this error #

  • PHPStan\Rules\Operators\InvalidIncDecOperationRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.