Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126030 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 D9DEA1A00BD for ; Sat, 23 Nov 2024 13:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1732367700; bh=Rnt+Oh6nV7GxBQHx7uhTi8HJE6algNYz/6EhI3HZQWM=; h=Date:From:To:Subject:From; b=RuVuK6VahYdd4m9tHw6cX+IZNcCog4QCW6BmKqrIM3ayiGX3wPicCCo0yBVA+Axrs YkJLma/V73hSKjWKlk52FCxrk3p8OnzvXpcB2/kRA95qPketjNHS/NyzE8hsyzrgSE xi8dvJbEk9LwNEy0hNgBh2esb57x2N7Pn2hyql8+E0E0DjpQowZ280v4ysyyzY1Q3a cpZycrZ65xsZk9/E/olXGLrm9XBV2lCZ8eE58b6HpYqMvGNeH8gCZZXP73+cHQU6oy Y5O7p2GgVICuLQHpeGgC2+g2sYFId4+0kmodbYdDim9wIn4YbX3c/zDMr+PJyXm2Ee uRF3Ovb4SgpmA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC224180078 for ; Sat, 23 Nov 2024 13:14:59 +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,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-b8-smtp.messagingengine.com (fout-b8-smtp.messagingengine.com [202.12.124.151]) (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, 23 Nov 2024 13:14:59 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id C7CCE114014E for ; Sat, 23 Nov 2024 08:12:17 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Sat, 23 Nov 2024 08:12:17 -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=fm2; t=1732367537; x=1732453937; bh=lrU9Lfi8fccZauMaomQL8TCkXdAtXtb0 3THjY7b86zk=; b=S0xpZ9Se9k2uGt2rottgPeamRELEpA8im6Kjkrmxt+hOOa6f lGbOJXs2oMl+kmRHemWp35jhyhwzVyNgW6b99d2kzv8K1LVklbzG/w6H2rJPw6QK Gjvto1DWS+u6i/jknKyvNJ8CdObDQy1aKrgjejUWiNu/l/+8du67Dd5fm3Z+RVzb iqrWhOZ/MQvZrBSYxAcAVCzFCW2DL4X6Xgh/on+TISqyAcdeGycd6ZHB0NsGDyOK 9NozuxQXIsZjEqouoeVoYyImURSmGh79QTHj7VbJb/4OCPu27TRkDh5Hcnoc0ajJ SO7JYkiTdbqGXHW7JvVUk90b4HEZn5A4Rg3oOg== 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=fm1; t=1732367537; x= 1732453937; bh=lrU9Lfi8fccZauMaomQL8TCkXdAtXtb03THjY7b86zk=; b=p PW2uzFNC4TA2ja4cHkD7GfbyhqcnirPnLFtYw56/wIb0BSNM4psNjr0YX0zH7hxU X2YKT0Fr+4+P9zOcQCCfnGTCMBuGgRql+wWIcQRbH2BJ7kqICMkQlLp1PTQyGXp7 Lp4dFaEajg0Os92fl//8d46S5rjfiGy4QBJQhN6HrqKZ//Jt9BwIUnujDOeMCCkL znWChiwKDL1hANvewh3n3rfbAruLhhVJJXvUsmpwtxUUAbcm3oDhA5xANbIA5SNU eHwPam+P/fA3gIlrsB47MZWyrHGJH4BFgtJnGOKOih3OWtJBsGc+jFoxErdtZw6n YzXAJuWu35bI7rX0Ao5sw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrgedugdeglecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggfffhvf fkufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhho sgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepfeekfeegvddtgf ettdevffffffefveekgefggfejleeukeeiuddvgeejheekleeinecuffhomhgrihhnpehp hhhprdhnvghtpdhgihhthhhusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggp rhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnh grlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 5E010780068; Sat, 23 Nov 2024 08:12:17 -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: Sat, 23 Nov 2024 14:11:56 +0100 To: internals@lists.php.net Message-ID: <18b85ba5-5f1c-489c-9096-3ae203977fbe@app.fastmail.com> Subject: [PHP-DEV] [RFC] Data Classes Content-Type: multipart/alternative; boundary=cc7d28b206ce48c3abef3a14d3fa4bbb From: rob@bottled.codes ("Rob Landers") --cc7d28b206ce48c3abef3a14d3fa4bbb Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello internals, Born from the Records RFC (https://wiki.php.net/rfc/records) discussion,= I would like to introduce to you a competing RFC: Data Classes (https:/= /wiki.php.net/rfc/dataclass).=20 This adds a new class modifier: data. This modifier drastically changes = how classes work, making them comparable by value instead of reference, = and any mutations behave more like arrays than objects (by vale). If des= ired, it can be combined with other modifiers, such as readonly, to enfo= rce immutability. I've been playing with this feature for a few days now, and it is surpri= singly intuitive to use. There is a (mostly) working implementation avai= lable on GitHub (https://github.com/php/php-src/pull/16904) if you want = to have a go at it. Example: data class UserId { public function __construct(public int $id) {} } $user =3D new UserId(12); // later $admin =3D new UserId(12); if ($admin =3D=3D=3D $user) { // do something } // true Data classes are true value objects, with full copy-on-write optimizatio= ns: data class Point { public function __construct(public int $x, public int $y) {} public function add(Point $other): Point { // illustrating value semantics, no copy yet $previous =3D $this; // a copy happens on the next line $this->x =3D $this->x + $other->x; $this->y =3D $this->y + $other->y; assert($this !=3D=3D $previous); // passes return $this; } } I think this would be an amazing addition to PHP.=20 Sincerely, =E2=80=94 Rob --cc7d28b206ce48c3abef3a14d3fa4bbb Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable