Skip to content

Incorrect non-ignorable "parameter is not contravariant" errors for constructors in subclasses where __construct() is in an interface #12830

@lkrms

Description

@lkrms

Bug report

When using an interface (I) to enforce a constructor signature on a class (A), the constructor parameters of subclasses are incorrectly checked for contravariance against the constructor of A, not I::__construct().

Code snippet that reproduces the problem

https://phpstan.org/r/823968be-46b6-4251-b541-7b34a88d6205

Expected output

If A adds optional arguments after parameters mandated by the interface, they should be excluded from consideration when checking subclass constructors.

This code should not trigger an error.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions