Error Identifier: possiblyImpure.functionCall
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);
/** @phpstan-pure */
function pureFunction(callable $callback): int
{
return $callback();
}
Why is it reported? #
A function marked as @phpstan-pure calls another function or callable whose purity is unknown. The called function or callable might have side effects, which would make the calling function impure. PHPStan cannot determine if the call is actually pure, so it reports it as possibly impure.
How to fix it #
Ensure the called function is also marked as pure, or remove the @phpstan-pure annotation:
<?php declare(strict_types = 1);
-/** @phpstan-pure */
-function pureFunction(callable $callback): int
+/** @phpstan-pure */
+function pureFunction(\Closure $callback): int
{
return $callback();
}
Or type the closure parameter with a @phpstan-pure callable type.
How to ignore this error #
You can use the identifier possiblyImpure.functionCall to ignore this error using a comment:
// @phpstan-ignore possiblyImpure.functionCall
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: possiblyImpure.functionCall