Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125975 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 qa.php.net (Postfix) with ESMTPS id D85DE1A00BD for ; Sat, 16 Nov 2024 23:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1731799070; bh=9t2IRxAKeawcSmxkAaBcLwIpXP2afJunpVaQ7yM8QoM=; h=Date:From:To:Subject:From; b=eQtGfzYLUutISiyXRBscYlTXi7uatZFENLQmDJgBdn6lDzaL2dPwM6g08kxpxLWZG SknIpCMSzWkS1FoQyC93F6e4wzFp7iiGsc0Q4hWdRwKEH0jwYTHIaGUnYzCUtRetBi 0xWyJ0N8aymDpN6zGS0frHG2ZjMLFkOKL5bt9i9Gpl1DJ/JVs2EsHiSQsC9XwZ1t+z tXTJFChY0vHcSb/RD6b+a/6TGslauoA8tVM2YG31HCbCzaEd0651mJ/NsLpwkjje6x G0zv8DfQ8K3hDkMH9wUu5n9/BA3aC9noiWkNT6FXAD41XjBa9s5zfxXbYBMZJdYss+ yBoneM5qM17jQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F3427180068 for ; Sat, 16 Nov 2024 23:17:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (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 ; Sat, 16 Nov 2024 23:17:47 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 3F1332540146 for ; Sat, 16 Nov 2024 18:15:09 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Sat, 16 Nov 2024 18:15:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm1; t=1731798909; x=1731885309; bh=e1Q5nsDdif7/gc9S/DvHwq4asQX3DJMZ riNWS1hkijg=; b=v36nLNaw4E8azxgDFdycNmwJl8yC9jjvMxbUDG2hB3Kxt0ug z+HedWvTNySLNh/yyO0Nf5qIttpdhwksAlW4srT/H5tOQwmbAIrmwzAX3hngjJgd TDDesGMt7JIiGRZq1vLNkaWZFGPqSwMcCZOWV9znOxQrt0ohjENAyQaN0LYT1uW/ SQe4LAlLwYHWi8SRkP6FI7XFYSTYfg+3aG0yvMjReDiTUkdTqlO/ooTLbmPeajgm U1+ARpTTV1LRVel4gAlMnrduwQtCND6jbYEFXfdiQK0Y7RHQ3NwObsd9csoIBe6N 7try37AycjV6nP9KmLdqhPjdReBjaW9foYQthw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1731798909; x= 1731885309; bh=e1Q5nsDdif7/gc9S/DvHwq4asQX3DJMZriNWS1hkijg=; b=U xJdOZpbcCClLTIOsU0OUYxYGQvwN7esZ+aT4d5UZp4J5c2Wlyrb1vU5FUtwR6fH6 YfZGmYwJnmwFkf/66/Rkmfg5s3MbO3ZkyjALJhAj3daATjYujEx/CxO7J31XKugH qg0wJXYnB148UZK1jGbN24gKrr91eVOoWWhUpVyJOWGB78f0fQyYGbpyrt4UkDxY ubJbxLbCQ6IzWS4i3jKpgElHza4Asg1F7T03krR7qXeNaLUnL4s/IhGJmE8iP6Yj wtHsIZFEgRpqrVEOJzjLvU/giXQwZ1lYqeViXs8XdKgmwXklv7gpnm/C51pQrv8W 4qwLiN9E/dRZno5FI8vcg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrvdejgddtjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggfffhvf fkufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhho sgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepveegkeejfeetud ejtdfgudfhtdeiieehhedvgeeiieduffejgfevvdelffejgeffnecuffhomhgrihhnpehp hhhprdhnvghtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtghpthhtohepuddpmhho uggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrph hhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id C4A0A780068; Sat, 16 Nov 2024 18:15:08 -0500 (EST) 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 Date: Sun, 17 Nov 2024 00:14:48 +0100 To: internals@lists.php.net Message-ID: Subject: [PHP-DEV] RFC: Records Content-Type: multipart/alternative; boundary=ab4d798070134d5892d74c6931547807 From: rob@bottled.codes ("Rob Landers") --ab4d798070134d5892d74c6931547807 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello internals, I'm ready as I'm going to be to introduce to you: "Records" https://wiki= .php.net/rfc/records! Records allow for a lightweight syntax for defining value objects. These= are superior to read-only classes due to having value semantics and far= less boilerplate, for most things developers use read-only classes for.= They are almost as simple to use as arrays (and provide much of the sam= e semantics), but typed. As an example, if you wanted to define a simple User record: record User(string $emailAddress, int $databaseId); Then using it is as simple as calling it like a function, with the & sym= bol: $rob =3D &User("rob@bottled.codes", 1); Since it has value semantics, we can get another instance, and it is str= ongly equal to another of the same parameters: $otherRob =3D &User("rob@bottled.codes", 1); assert($otherRob =3D=3D=3D $rob); // true Records may also have methods (even hooks), use traits, and implement in= terfaces: 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) } } Further, an automatic (but overridable) "with" method is generated for e= very record. This allows you to get a new record similar to a given one,= very easily: record Planet(string $name); $earth =3D &Planet("earth"); $mars =3D $earth->with(name: "mars"); The depth of records was an immense exploration of the PHP engine, langu= age design, and is hopefully quite powerful for the needs of everyday PH= P and niche libraries. I took care in every aspect and tried to cover ev= ery 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 op= en 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 --ab4d798070134d5892d74c6931547807 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hello internals= ,

I'm ready as I'm going to be to introduce= to you: "Records" htt= ps://wiki.php.net/rfc/records!

Records = allow for a lightweight syntax for defining value objects. These are sup= erior to read-only classes due to having value semantics and far less bo= ilerplate, for most things developers use read-only classes for. They ar= e almost as simple to use as arrays (and provide much of the same semant= ics), but typed.

As an example, if you want= ed to define a simple User record:

record U= ser(string $emailAddress, int $databaseId);

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

$rob =3D &User("rob@bottled.codes", 1);

Since it has value semantics, we can get another instance, and = it is strongly equal to another of the same parameters:
$otherRob =3D &User("rob@bottled.codes", 1);
assert($otherRob =3D=3D=3D = $rob); // true

Records may also have method= s (even hooks), use traits, and implement interfaces:

=
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)
  }
}

Further, an automatic (but overridable)= "with" method is generated for every record. This allows you to get a n= ew record similar to a given one, very easily:

<= div>record Planet(string $name);

$earth =3D= &Planet("earth");
$mars =3D $earth->with(name: "ma= rs");

The depth of records was an immense e= xploration of the PHP engine, language design, and is hopefully quite po= werful 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 s= till 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, b= ut 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
--ab4d798070134d5892d74c6931547807--