Re: [RFC][Discuss] Covariant return- and contravariant parameter- types
| From: | Larry Garfield | Date: | Tue, 27 Nov 2018 21:16:05 +0000 |
| Subject: | Re: [RFC][Discuss] Covariant return- and contravariant parameter- types | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103524@lists.php.net to get a copy of this message | ||
On Tuesday, November 27, 2018 3:00:27 PM CST Levi Morrison wrote:
> On Tue, Nov 27, 2018 at 11:36 AM Larry Garfield <larry@garfieldtech.com>
wrote:
> > Looks like fun!
> >
> > Would this also include allowing a return type of
Attachment: [application/pgp-signature] This is a digitally signed message part. signature.asc
static,
> > which would be
> > useful for the "Return the object that was invoked" case or "return a new
> > instance of the same object" case? Currently we're limited to `return
> > self`, which is, of course, not the same thing and less flexible.
> >
> > --Larry Garfield
>
> It does not. To be honest, I did not think of it until your question.
On Tuesday, November 27, 2018 3:04:30 PM CST Marcos Passos wrote:
> Supporting static return would come in handy to define
> interfaces for
> immutable objects.
Exactly the sort of use case I was thinking of. Or for builder objects, where
you mutate the object in place and then return it. That's a common pattern,
but return self and subclasses don't play that nicely there.
Levi, is that something that could be reasonably added to this RFC or is that
Hard(tm), like scalar/callable/etc?
(I don't know that a static/self parameter declaration is even a thing, so it
probably doesn't matter there; it does matter for returns, though.)
--Larry Garfield
Attachment: [application/pgp-signature] This is a digitally signed message part. signature.asc