Re: [RFC] Primary Constructors
| From: | Rowan Tommins [IMSoP] | Date: | Mon, 29 Jun 2026 17:11:49 +0000 |
| Subject: | Re: [RFC] Primary Constructors | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131594@lists.php.net to get a copy of this message | ||
On 29 June 2026 17:40:29 BST, Larry Garfield <larry@garfieldtech.com> wrote:
>For anon classes, I would think the best approach is to have a compact, non-redundant syntax for
>"take this value from current scope and assign it to a property in this class." Basically
>combining promotion and closure. Doing that right now is horribly ugly.
Yeah, that was precisely my starting point. The "use" syntax I came up with felt pretty
clear and flexible, but some off-list review suggested that fabricating a constructor behind the
scenes was not ideal, because there are use cases for combining it with a real constructor.
I was looking into alternative ways to inject the values into the instance, such as an extra opcode
like the one closures use; but Real Life intervened and I haven't got back to it for a while.
I would need to look back at notes and discussions to see if there were use cases mentioned other
than parent constructor calls. Maybe the "parameter forwarding" syntax from this RFC could
be combined with what I had somehow.
Rowan Tommins
[IMSoP]