You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should this 'Parameter of method SubClass::__construct() is not contravariant with parameter of method ParentClass::__construct()' error be unignorable? #12272
Parameter #2 $code (int) of method SpecificException::__construct() is not contravariant with parameter #2 $previous (Throwable|null) of method BaseException::__construct().
and when I try to add a similar error to the baseline on a project, PHPStan reports that: Unignorable errors could not be added to the baseline.
The code in question could probably have a better structure, but it doesn't generate any PHP warnings or errors: https://3v4l.org/abZFe, so I'm wondering whether that PHPStan error should be marked as unignorable or reported at all. This old issue suggests to me that doing this type of check on the constructor methods may be an accident.
I think PHPStan should either allow the error to be ignored or don't report an error.
Did PHPStan help you today? Did it make you happy in any way?
I rely on PHPStan every day. It makes code reviews much easier because I can focus on the solution approach and business needs knowing that PHPStan is checking our code for other problems.
changed the title [-]Should this 'Parameter SubClass::__construct() is not contravariant with parameter ParentClass::__construct()' error be unignorable?[/-][+]Should this 'Parameter of method SubClass::__construct() is not contravariant with parameter of method ParentClass::__construct()' error be unignorable?[/+]on Dec 16, 2024
@ondrejmirtes this code is perfectly valid in PHP: https://3v4l.org/LFC0S
A constructor does not need to be contravariant with a parent constructor. Only interfaces enforces some constructor signature for child classes, but SpecificException is contravariant with the signature of the interface it implements.
Activity
ondrejmirtes commentedon Dec 16, 2024
This is a legit bug which should be fixed.
[-]Should this 'Parameter SubClass::__construct() is not contravariant with parameter ParentClass::__construct()' error be unignorable?[/-][+]Should this 'Parameter of method SubClass::__construct() is not contravariant with parameter of method ParentClass::__construct()' error be unignorable?[/+]stof commentedon Dec 21, 2024
@ondrejmirtes this code is perfectly valid in PHP: https://3v4l.org/LFC0S
A constructor does not need to be contravariant with a parent constructor. Only interfaces enforces some constructor signature for child classes, but
SpecificExceptionis contravariant with the signature of the interface it implements.ondrejmirtes commentedon Dec 21, 2024
Yes, I already stated this is a PHPStan bug that should be fixed. Otherwise I'd close this issue.
phpstan-bot commentedon Feb 26, 2026
Closed via merging phpstan/phpstan-src#4945
github-actions commentedon Mar 30, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.