Re: RFC: Records

From: Date: Thu, 21 Nov 2024 23:07:35 +0000
Subject: Re: RFC: Records
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-126029@lists.php.net to get a copy of this message
On Sun, Nov 17, 2024, at 08:21, Larry Garfield wrote: > I would far prefer assembling record-ish behavior myself, using the smaller parts above. Eg: > > final readonly data class Point(int $x, int $y); > > "final" prevents extension. "readonly" makes it immutable. > "data" gives it value-passing semantics. Any class can use an inline constructor.. > "with" is designed to work automatically on all objects. Boom, I've just assembled a > Record out of its constituent parts, which also makes it easier for others to learn what I'm > doing, because the features opted-in to are explicit, not implicit. Sorry for the radio silence, but I found myself saying something was impossible. This is software, anything is possible... Anyway, I think I figured out how to implement a "data" modifier, and it is quite excellent (for the exact reasons you give). I'll break this up into multiple RFCs, pending some further tests to try and break my proof-of-concept: - a "data" modifier on class for value semantics - an "inline constructor" As you mention, at that point, a "record" or "value" keyword can just be shorthand for "final readonly data class". — Rob

« previous php.internals (#126029) next »