Re: [RFC][Vote] Return Types
| From: | Andrea Faulds | Date: | Thu, 06 Nov 2014 00:57:25 +0000 |
| Subject: | Re: [RFC][Vote] Return Types | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78762@lists.php.net to get a copy of this message | ||
> On 6 Nov 2014, at 00:26, Andrea Faulds <ajf@ajf.me> wrote:
>
>> Also, it is kind of weird that arguments require exact match but return
>> types do not. Not that we care for consistency anymore…
>
> Yeah, we should probably have arguments be contravariant or covariant.
>
> I was going to argue that covariance is important, but now that I think about it, the most
> important case is just self. If I can have Foo::foo() return a Foo and Bar::foo() return a Bar, with
> Bar inheriting from Foo, and this not breaking the invariant type check, I’m happy.
What I meant there wasn’t
self, but actually static, I think, which
sadly this RFC doesn’t provide. I think that’d be a very useful feature. If we can’t get
covariant returns and must go for invariants, I think we’d have to have static
supported.
I note that Hack also has invariant parameters and covariant return types. There’s probably some
good reasoning behind that, I think it’d be worth asking some HHVM people about why that decision
was taken, they might provide some useful insight.
--
Andrea Faulds
http://ajf.me/