← Back to paramImmediatelyInvokedCallable.*
Error Identifier: paramImmediatelyInvokedCallable.nonCallable
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);
/**
* @param-immediately-invoked-callable $callback
*/
function doFoo(string $callback): void
{
}
Why is it reported? #
The @param-immediately-invoked-callable PHPDoc tag is applied to a parameter whose native type is not callable. This tag is used to tell PHPStan that a callable parameter will be invoked immediately within the function (not stored for later use), which affects type narrowing. When the parameter type is not callable, the tag has no meaning.
How to fix it #
Change the parameter type to a callable type:
/**
* @param-immediately-invoked-callable $callback
*/
-function doFoo(string $callback): void
+function doFoo(callable $callback): void
{
}
Or remove the tag if the parameter is not intended to be callable:
-/**
- * @param-immediately-invoked-callable $callback
- */
function doFoo(string $callback): void
{
}
How to ignore this error #
You can use the identifier paramImmediatelyInvokedCallable.nonCallable to ignore this error using a comment:
// @phpstan-ignore paramImmediatelyInvokedCallable.nonCallable
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: paramImmediatelyInvokedCallable.nonCallable
Rules that report this error #
- PHPStan\Rules\PhpDoc\IncompatibleParamImmediatelyInvokedCallableRule [1]