Back to Phpstan

preInc.expr

website/errors/preInc.expr.md

2.2.1554 B
Original Source

Code example

php
<?php declare(strict_types = 1);

function doFoo(): int
{
	return 5;
}

++doFoo();

Why is it reported?

The increment operator (++) is applied to an expression that is not a variable. The ++ operator requires an assignable expression (a variable, array element, or property). In the example above, doFoo() is a function call result, which cannot be incremented.

How to fix it

Apply the operator to a variable instead:

diff-php
 <?php declare(strict_types = 1);

-++doFoo();
+$value = doFoo();
+++$value;