On Mon, Mar 15, 2021 at 2:16 PM Matthew Brown <matthewmatt...@gmail.com>
wrote:

> On Sun, 14 Mar 2021 at 18:09, Rowan Tommins <rowan.coll...@gmail.com>
> wrote:
>
> > Are you saying that having the parent::getSomeInt() call fail would be
> > problematic?
> >
> >
>  Yes, that's where this becomes unsound – you can call the child method
> statically, but the parent call assumes a dynamic instance.
>
> This is just my perspective (as someone building a tool that helps prevent
> people from shooting themselves in the foot), but PHP should not allow
> _more_ unsound behaviour than it already does.
>

I'm not sure I follow your point. The fact that something is compatible,
does not mean that you can just blindly perform a forwarding call. For
example, consider this:

class A {
    public function method(string $x) {}
}

class B extends A {
    public function method(string|int $x) {
        parent::method($x);
    }
}

B::method() is compatible with A::method() from a typesystem perspective.
But that doesn't mean that a parent::method() call will work. The above
code is simply an implementation bug in B::method(), but doesn't say
anything fundamental about the compatibility of the signatures. I would
argue that the same holds in your example.

Disclaimer: I have some serious doubts that allowing non-static->static
changes is worthwhile, I just don't see why it would be outright unsound.

Regards,
Nikita

Reply via email to