Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128160 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id E45131A00BC for ; Mon, 21 Jul 2025 11:57:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753098923; bh=r/m83sMwHuAB89Oc2a7NOyJ8Wv/JzKTairADqTXxXTA=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=Te3B7XGQzX2V61BV5TP/5JyDDZIjhr6Mnd1d8vZ0tBwMBnUZc3Eu2ceKmsdNVIzx2 HrzUkq7KnwjwnVC16KtpPwp57ADaOwYk1MSdN8GzSJ6PyKTOexgqZWuv4DZWZPvVGC iX/nd9EP0npB8ki6Y4iYsAXEmYxb219RqV8Jf+9kX/Wc8e5eVD+vhcNvPOUIacPNTf hR8kD2tev6aFToLQExFcu+ExfhaxqMMFcnUuRiyinhQaKp5c0Mfsw9qEUCqsZiXVr5 roFqD62VRW9rEN4Qz3Ul5cUtNpmr4RuVQs1aNOArdX32CxpP9Mk1IfP/RNpU7cTCcd udpgkFjUXaICg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8F637180057 for ; Mon, 21 Jul 2025 11:55:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b1-smtp.messagingengine.com (fhigh-b1-smtp.messagingengine.com [202.12.124.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 21 Jul 2025 11:55:22 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 01D747A037A; Mon, 21 Jul 2025 07:57:06 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Mon, 21 Jul 2025 07:57:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1753099026; x= 1753185426; bh=Nh13aWxpytMh4VTM2jHSXu0mvQYxEoKBgY5j3RKr2NI=; b=W ta8TJbQm3MvQGEDdjcIOmlUR9DUjwlqjcOeeVAYy4xSJIQrXQNlxIyhTJa6KaEsL CQENEQoCAUMuxOLSINt8+bUl+gBFSs0Tl4Mj5loU+QpMoj/jVgS8xvA8DMnaNb3f FdM0UlM74nqdgK7DXyYJzw9IC6vOjCjfTJdKqdJ5DIExLLeBwgKglS/qv9Wrvr26 Oy+ru60/Hi5EWllSziujyZ3gB4vOVSs45SeRhWFg0rPnO0AyF83lwkZ5IL4M5cvA x6TszxXMVTA5S4aFQpsCzu65ixSL2WLSfI3o3/VBhufA596IE+TJUR6F/XmSudF4 1nXonGEbojGcjkK3tvAcw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1753099026; x=1753185426; bh=Nh13aWxpytMh4VTM2jHSXu0mvQYxEoKBgY5 j3RKr2NI=; b=i+8lv80kXccLBT/RC7mrJV/r06G6m94ZzaGsKBWpg/+Yk78ccWQ XK/1Bg2Pd8ePWNVlO2909FGxER4JtsmAyY/zZ/LkTu4L6hFu3snzE4XI9Fk9DQOD vLMXEwb539AbF3p3VSpMYgxL0vd6JmPucqswvvNUhpTqlHzB9M5o4IOC7Nvtg8iX muzQMoXhZyImpeEFiXeU6Z6a4MjgxDwgzJOhspC3Fz4HWbzpm8jLVLOxPTB+B+0J CIEWpSC0cTkHOqaUFSfdgJlSWNIu/7J67QfHQyu5JxDtnQs5f0VB9C4sTUoUGwap dXHt45X60q6INR4IcvsBb9/FCWJnlumcbtg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejvddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerre dtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggu rdgtohguvghsqeenucggtffrrghtthgvrhhnpeffgeevveegtdffgfffvdfftddvheeule egveekteffueeliedtgeekjeettdetkeenucffohhmrghinhepphhhphdrnhgvthenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsoh htthhlvggurdgtohguvghspdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvghtpdhrtg hpthhtohepphhhphesnhhitghkshguohhtrdguvghv X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id C84B11820074; Mon, 21 Jul 2025 07:57:05 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: Ta3f42e4d0ede798b Date: Mon, 21 Jul 2025 13:56:45 +0200 To: Nick Cc: internals@lists.php.net Message-ID: <3077f8b7-1b26-4e1f-9875-aabfd8b5046d@app.fastmail.com> In-Reply-To: <6E26E32F-40D3-4C31-A9CB-6A8BC6CE76E4@nicksdot.dev> References: <6E26E32F-40D3-4C31-A9CB-6A8BC6CE76E4@nicksdot.dev> Subject: Re: [PHP-DEV] RFC: Records Content-Type: multipart/alternative; boundary=143416e930a34b7d9c9b7107d84a87a1 From: rob@bottled.codes ("Rob Landers") --143416e930a34b7d9c9b7107d84a87a1 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Jul 21, 2025, at 13:02, Nick wrote: >=20 >> On 17. Nov 2024, at 06:14, Rob Landers wrote: >>=20 >> Hello internals, >>=20 >> I'm ready as I'm going to be to introduce to you: "Records" https://w= iki.php.net/rfc/records! >>=20 >> Records allow for a lightweight syntax for defining value objects. Th= ese are superior to read-only classes due to having value semantics and = far less boilerplate, for most things developers use read-only classes f= or. They are almost as simple to use as arrays (and provide much of the = same semantics), but typed. >>=20 >> As an example, if you wanted to define a simple User record: >>=20 >> record User(string $emailAddress, int $databaseId); >>=20 >> Then using it is as simple as calling it like a function, with the & = symbol: >>=20 >> $rob =3D &User("rob@bottled.codes", 1); >>=20 >> Since it has value semantics, we can get another instance, and it is = strongly equal to another of the same parameters: >>=20 >> $otherRob =3D &User("rob@bottled.codes", 1); >> assert($otherRob =3D=3D=3D $rob); // true >>=20 >> Records may also have methods (even hooks), use traits, and implement= interfaces: >>=20 >> record Vector3(float $x, float $y, $z) implements Vector { >> use Vector; >> public float magnitude { >> get =3D> return sqrt($this->x ** 2 + $this->y ** 2 + $this->z ** = 2) >> } >> } >>=20 >> Further, an automatic (but overridable) "with" method is generated fo= r every record. This allows you to get a new record similar to a given o= ne, very easily: >>=20 >> record Planet(string $name); >>=20 >> $earth =3D &Planet("earth"); >> $mars =3D $earth->with(name: "mars"); >>=20 >> The depth of records was an immense exploration of the PHP engine, la= nguage design, and is hopefully quite powerful for the needs of everyday= PHP and niche libraries. I took care in every aspect and tried to cover= every possible case in the RFC, but I still probably missed some things= . I plan on having a full implementation done by the end of the year and= open to a vote by the end of January, but I'd like to open the discussi= on up here first. Love it or hate it, I'd like to hear your thoughts. >>=20 >> =E2=80=94 Rob >=20 >=20 > Hey Rob, >=20 > We just discussed your RFCs here. We noticed this in the RFC: >=20 > ```php > $point1 =3D &Point(3, 4); > $point2 =3D $point1; // No data duplication, $point2 references the sa= me data as $point1 > $point3 =3D Point(3, 4); // No data duplication, it is pointing to the= same memory as $point1 > ``` >=20 > Is the `&` on the 3rd line `Point` omitted intentionally or was that j= ust missed? > If not missed, how is that not ambiguous? >=20 > Could you please clarify? >=20 > *Cheers,* > Nick The & was originally a way to signal to the engine that this was going t= o be a Record (for autoloading) but I think I realized it is actually va= lid PHP code? I don't remember why I removed it specifically. I like the= Point::(3, 4) syntax, when I think about it. =E2=80=94 Rob --143416e930a34b7d9c9b7107d84a87a1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Mon, Jul = 21, 2025, at 13:02, Nick wrote:

On 17. Nov 2024, at 06:14, Rob Landers <rob@bottled.c= odes> wrote:

Hello internals,

I'm ready a= s I'm going to be to introduce to you: "Records" https://wiki.php.net/rfc/records!

Records allow for a lightweight syntax for defin= ing value objects. These are superior to read-only classes due to having= value semantics and far less boilerplate, for most things developers us= e read-only classes for. They are almost as simple to use as arrays (and= provide much of the same semantics), but typed.

As an example, if you wanted to define a simple User record:

record User(string $emailAddress, int $datab= aseId);

Then using it is as simple as cal= ling it like a function, with the & symbol:

$rob =3D &User("rob@bott= led.codes", 1);
Since it has value se= mantics, we can get another instance, and it is strongly equal to anothe= r of the same parameters:

$otherRob =3D &= amp;User("rob@bottled.codes", 1= );
assert($otherRob =3D= =3D=3D $rob); // true
<= br>
Records may also ha= ve methods (even hooks), use traits, and implement interfaces:

record Vector3(float $x, float $y, $z) implements = Vector {
  use Vec= tor;
  public floa= t magnitude {
  &n= bsp; get =3D> return sqrt($this->x ** 2 + $this->y ** 2 + $this= ->z ** 2)
  }
}

Further, an automatic (but overridable) "with" method is genera= ted for every record. This allows you to get a new record similar to a g= iven one, very easily:
=
record Planet(stri= ng $name);

$earth =3D &Planet("earth"= );
$mars =3D $earth->= ;with(name: "mars");
The depth of records= was an immense exploration of the PHP engine, language design, and is h= opefully quite powerful for the needs of everyday PHP and niche librarie= s. I took care in every aspect and tried to cover every possible case in= the RFC, but I still probably missed some things. I plan on having a fu= ll implementation done by the end of the year and open to a vote by the = end of January, but I'd like to open the discussion up here first. Love = it or hate it, I'd like to hear your thoughts.

=E2=80=94 Rob


Hey Rob,

We= just discussed  your RFCs here. We noticed this in the RFC:
<= div>
```php
$point1 =3D &= Point(3, 4);
$point2 // No da= ta duplication, $point2 references the same data as $point1
$p= oint3 =3D Point(3, 4); // No data duplication, it is pointi= ng to the same memory as $point1
```<= /div>

Is the `&` on the 3rd line `Point` omitted = intentionally or was that just missed?
If not missed, how is t= hat not ambiguous?

Could you please clarif= y?

Cheers,
Nick

The & was originally a way to signal to the = engine that this was going to be a Record (for autoloading) but I think = I realized it is actually valid PHP code? I don't remember why I removed= it specifically. I like the Point::(3, 4) syntax, when I think about it= .

=E2=80=94 Rob
--143416e930a34b7d9c9b7107d84a87a1--