Skip to content

Should this 'Parameter of method SubClass::__construct() is not contravariant with parameter of method ParentClass::__construct()' error be unignorable? #12272

@wvega

Description

@wvega

Bug report

The code from https://phpstan.org/r/28422159-3b33-499a-9c14-0856c73bf57b generates the following error:

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.

Note that when I remove the ExceptionContract interface from the example, PHPStan no longer detects an error: https://phpstan.org/r/baca06c9-6103-445b-92ec-a0c945ab6d62

Code snippet that reproduces the problem

https://phpstan.org/r/28422159-3b33-499a-9c14-0856c73bf57b

Expected output

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions