Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126037 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 BCB9E1A00BD for ; Sat, 23 Nov 2024 17:35:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1732383512; bh=W0suQvpW9s1c2reTOP4RqBhW5uGvMrLvSP5s4D6ZsK0=; h=Date:From:To:In-Reply-To:References:Subject:From; b=SqSuTzlWC4s/qlhZfuyYyVFF2BHp1UbU3dpCm+hxOZTg80rY/9JdvMMj9y8DjyK+P 3PeuXe52qYWQ6JbfZI10tYl1XRSX8ZwEsguA3KCO0IlQrVAFl7f6OYEfL10tqYsfHJ 3ZOH8QU5YVolSZrCldJEpUKcf7xh4EYhtceHMDjLptPbhKsQwOknre470mxxSn+cXO 65qbWSRnvoZz9mn9fujKjNJWSDfuvPSeqo8cYdJluTPtoa+jw0C7mvoVnHwVJia3YI +DhWQSl8Px2tqrssSRbDm/B+poYbwbR0df3hriP7+1K0PkyD2gBah8vY+VxHEQDXJU AYhlznge84YHA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 391ED1801DE for ; Sat, 23 Nov 2024 17:38:30 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.135]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) 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 17:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thomasbley.de; s=s1-ionos; t=1732383342; x=1732988142; i=mails@thomasbley.de; bh=XHjqI+bPQwGQ+Yh2S2JXDhmw7d6VmIqzcMgdOo+c8f4=; h=X-UI-Sender-Class:Date:From:To:Message-ID:In-Reply-To:References: Subject:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=L4pjhUw7ZkEHXHUrfDhKPlOE5mg9OJIJQrL9E4dekwRNaqjkj3refbXikpkyVTHg XYOX07nYoRF1oxmbl0/dXYc3tl+wCizbsLLt+bSKl93kNrPQnjLo9KBUGD5CsKJxT seGp7LsK2bu1vvy5CzoGOw3Wb5HL7rBw+Mjbi5SZP+h6IRyKa80ojeQPh4a2nSnzd tV61ooV3ZKfDNf38Uur9PxQXf53dBy+It7xz1jFSgLuQNHEubaAZ4YsiYV5Zrd3/B a+fg/2RoR7tyeA9AkVYrfVdUSe9syACmV4fNwGwUu3VLAbKqg3AALO7QL02f8S8g6 Kc8kJBc5eY54lC27pA== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from open-xchange-core-mw-default-7.open-xchange-core-mw-hazelcast-headless.open-x change.svc.cluster.local ([10.73.157.244]) by mrelayeu.kundenserver.de (mreue012 [172.19.35.3]) with ESMTPSA (Nemesis) id 1MVaQW-1t7JJB3UbE-00O7rD; Sat, 23 Nov 2024 18:35:41 +0100 Date: Sat, 23 Nov 2024 18:35:41 +0100 (CET) To: Rob Landers , internals@lists.php.net Message-ID: <1438199905.177050.1732383341616@email.ionos.de> In-Reply-To: <18b85ba5-5f1c-489c-9096-3ae203977fbe@app.fastmail.com> References: <18b85ba5-5f1c-489c-9096-3ae203977fbe@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Data Classes Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_177049_1858200201.1732383341610" X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v8.26.37 X-Originating-Client: open-xchange-appsuite X-Provags-ID: V03:K1:aAhSxL+iu6z0e4ISvCDlnEi5tR1IOf+1eOO5Sqh+ng4Js6GmQDw 6+0DJ/oW3VZTfXZ96gvAl2vqRWv9eQNvE7UIvAglM4BWBqATYih4NnvCsLYZuO4uKMOAnRC sfCdPb+qIapNsHg2Wo/mrLUKKAERUZyXGefqEsVxqJiAsjJkCtonU22pfnR4GmdNl5g1pqG 7c5O+/+/bOdB0SIMplkjw== UI-OutboundReport: notjunk:1;M01:P0:cL5nfVt0FGM=;cDO896+aZzzY54R9B0uAJhUYjcU VNEDaVvwpVgck8mhA+Ulu+wHF+ucAUhupjf63NJPXEy9G3KZgu8ZQoku/T1gweNuCXWpUVQcI CC7mVAkXDNzNH4hUg9Rnovml0/uD1XV8UeP/JFL6yzH7K/RTv33LNUjJ85Wwie97H6VuPjsN5 H66juC+UOnS1GXZNy69779gMhrKVH1+fQnEVvPKY7OfUQiMjcvg7kTtcFYQsW4waf7O9TC1ky R9FisUHXRGIG9YiSJwuiehZJjc29AAl81mBX/fwzALwDKlITbP0hTY01r515ZkxQWQcs8UutV rFw1p00zAR+rLjMXF75dNxyoamWkcRDS/FheEwACMf9cMYhXpQbCeAvevoOM/sw0np2ijNbjq tEeQpC0VTo9ma0AhOBZUFPcm9mCaix70uqcT8eupwc96qKG0iuOLcy5G58Cn9YPG6dUuxgROi xNKXj9ETa7uYazbJELzY1pFOjZ+yfdBPMr6osrqbYJAGVISo5eyLctmHrm1cejDVwnZWbs40j v57hKcXr8IC80nUWiZmUSMJvHXapyzt5CuoKEGLlamGLTGayquIndaPuSNDCcHTkM8flX1drc 7IYT1EaVJI6dWZRsXyAjeskMF3tj6QshybeQPZFf0lJfWqHYp7k2DfpUcp6FFQ8t87pij0JaM 9pkXW2+U3vp/fhXeLksPlBPcOu1lsfyTd3GvRUnFJzNE3UNnDTgZDN2WVImkrwtMIgY2iFyTC RGh1jej2aR0KC0r4MMnxBshgUukKEiZTmMVZZZr4uqrR/X+oSxR20je3WFQoWtHu40gMyqJgv cGgKa/vDbDsT9/pVGHV9VpS8Uy3vOzLeudQPwL14S65kw= From: mails@thomasbley.de (Thomas Bley) ------=_Part_177049_1858200201.1732383341610 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable =20 > Rob Landers hat am 23.11.2024 14:11 CET geschrieben: > =20 > =20 > Hello internals, > =20 > 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://wik= i.php.net/rfc/dataclass).=20 > =20 > This adds a new class modifier: data. This modifier drastically changes h= ow classes work, making them comparable by value instead of reference, and = any mutations behave more like arrays than objects (by vale). If desired, i= t can be combined with other modifiers, such as readonly, to enforce immuta= bility. > =20 > I've been playing with this feature for a few days now, and it is surpris= ingly intuitive to use. There is a (mostly) working implementation availabl= e on GitHub (https://github.com/php/php-src/pull/16904) if you want to have= a go at it. > =20 > Example: > =20 > data class UserId { public function __construct(public int $id) {} } > =20 > $user =3D new UserId(12); > // later > $admin =3D new UserId(12); > if ($admin =3D=3D=3D $user) { // do something } // true > =20 > Data classes are true value objects, with full copy-on-write optimization= s: > =20 > 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; > } > } > =20 > I think this would be an amazing addition to PHP.=20 > =20 > Sincerely, > =20 > =E2=80=94 Rob >=20 =20 Thanks for the rfc! From userland perspective I would prefer to have the cloning more explicitl= y, e.g. return clone $this($this->x + $other->x, $this->y + $other->y); =20 or =20 return clone $this(x: $this->x + $other->x); // clone with y unchanged =20 Best Regards Thomas ------=_Part_177049_1858200201.1732383341610 MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
 
Rob Landers <rob@bottled.codes> hat am 23.11.2024 14:11 CET gesch= rieben:
 
 
Hello internals,
 
Born from the Records RFC (https://wiki.php.net/rfc/records) discussion, I would like to introduc= e to you a competing RFC: Data Classes (https://wiki.php.net/rfc/dataclass). 
 
This adds a new class modifier: data. This modifier drastically changes= how classes work, making them comparable by value instead of reference, an= d any mutations behave more like arrays than objects (by vale). If desired,= it can be combined with other modifiers, such as readonly, to enforce immu= tability.
 
I've been playing with this feature for a few days now, and it is surpr= isingly intuitive to use. There is a (mostly) working implementation availa= ble 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 optimizati= ons:
 
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. 
 
Sincerely,
 
=E2=80=94 Rob
 
Thanks for the rfc!
From userland perspective I would prefer to have the cloning more explic= itly, e.g.

return clone $this($this->x + $other->x, $this->y + $other->= y);
 
or
 
return clone $this(x: $this->x + $other->x); // clone with y uncha= nged
 
Best Regards
Thomas
------=_Part_177049_1858200201.1732383341610--