Re: Parameter type widening RFC

From: Date: Fri, 26 May 2017 16:10:29 +0000
Subject: Re: Parameter type widening RFC
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-99206@lists.php.net to get a copy of this message
On Fri, May 26, 2017 at 9:01 AM, lists@rhsoft.net <lists@rhsoft.net> wrote: > > > Am 26.05.2017 um 16:26 schrieb Dan Ackroyd: > >> On 26 May 2017 at 13:23, lists@rhsoft.net <lists@rhsoft.net> wrote: >> >>> does that also fix the issue >>> https://bugs.php.net/bug.php?id=74394 >>> >> >> >> Dear Anonymous, >> >> That "issue" is actually 3 issues. >> >> case 1 >> >> class A { >> public function test($a) {} >> } >> class B extends A { >> public function test(string $a) { } >> } >> >> This breaks LSP - because B::test doesn't accept all the things that >> A::test can accept and so is unlikely to ever be supported. >> > > and how is that a problem? > > A accepts anything > B limits it's inut to a *subset* of "anything" > > Because, if I have a function foo(A $a) { $a->test(new Bar()) } that I cannot pass B into this function, even though it is a subclass of A. You should be able to pass any subclass where its parent is expected, allowing parameter narrowing (covariance) would break this.

« previous php.internals (#99206) next »