On Tue, Jun 16, 2020 at 8:59 AM Mike Schinkel <m...@newclarity.net> wrote:

> Hi internals,
>
> Given that there appears to be some appetite to reduce checks for
> inappropriate signatures[1] I am wondering if anyone has strong opinions —
> pro or con — on removing checks for static methods?
>
> My primary use-case where I would like to see checked relaxed is for
> static methods used as factory methods[2].
>
> Per [3] it seems that all but the least upvoted answer argues that LSP
> applies to instances, not static methods.
>
> Per [4] it seems that all upvoted answers agree that constructors should
> not be constrained by LSP, and since a factory method is a form of a
> constructor it would seem that if constructors do not require LSP then
> factory methods would not either.
>
> Does anyone see any issues with relaxing these checks for static methods
> that would have them downvote an RFC on the topic?
>

Hi Mike,

The problem here is that static methods signatures are subject to LSP if
they are used in conjunction with late static binding (LSB):

class A {
    public static function test() {
        static::method();
        // May call A::method(), B::method() or any child.
        // Signature must match for this to be sensible!
    }
}
class B extends A {
}

I do agree that the current situation is sub-optimal, because certainly not
all static methods actually are used with LSB. But we do not presently
distinguish these cases.

If that problem can be addressed in some way, then I agree that (non-LSB)
static methods should be exempt from LSP, just like constructors are.

Regards,
Nikita

Reply via email to