Menu
Error Identifier: paramClosureThis.nonClosure
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);
class Foo
{
/**
* @param-closure-this Foo $callback
*/
public function register(callable $callback): void
{
}
}
Why is it reported? #
The @param-closure-this PHPDoc tag is used on a parameter whose type is not Closure. The @param-closure-this tag specifies the $this context inside a Closure, so it only makes sense for parameters typed as Closure. Other callable types (like callable) do not bind a $this context.
How to fix it #
Change the parameter type to Closure:
<?php declare(strict_types = 1);
class Foo
{
/**
* @param-closure-this Foo $callback
*/
- public function register(callable $callback): void
+ public function register(\Closure $callback): void
{
}
}
How to ignore this error #
You can use the identifier paramClosureThis.nonClosure to ignore this error using a comment:
// @phpstan-ignore paramClosureThis.nonClosure
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: paramClosureThis.nonClosure