"Parameter #1 expects A<covariant B>, A<B> given" error since 2.2.13
Author: LastDragon-ruCreated Sep 15, 2026Updated Sep 15, 2026
Bug report
/**
* @template T of object
*/
class A
{
/**
* @param T $object
*/
public function __construct(public object $object) {}
}
class B {
/**
* @param A<covariant static> $a
*/
public function method(A $a): void {}
}
class D {
public function inconsistent(B $b): void {
$b->method(new A($b)); // (!) No error.
}
}
$b = new B();
$b->method(new A($b)); // (!) Parameter #1 $a of method B::method() expects A<covariant B>, A<B> given.Code snippet that reproduces the problem
https://phpstan.org/r/62abfe0c-e730-46e2-9b60-8640d9f4f862
Expected output
No error.
Did PHPStan help you today? Did it make you happy in any way?
Yep
Source: phpstan/phpstan