Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128018 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 78ED11A00BC for ; Sun, 13 Jul 2025 11:11:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752404991; bh=rsguUO7MBD4Cpzdk5k1qEvrH72aof0x2iYb4GPOFR8I=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=KG7E+viwooLfMU6hofPkfvxdFPYcxwV9PQj9MisqEO7hN0TGDm0+0ZU8S+i2/jxea 5g4UUTpFihMhQZI5ILrpY+7rwaeIakchtF0dTFxu4YinldiInYgfS84zwg/Kc8QSbS JHAtskEfQPz+p5O/jKb95PyQgYm7plos75NRWj91O4Dw7vgJ8eD/fsRL/WsYBRV0Fj SDakkfS96YzOk6MZyq6Vn6QpR7Ou4tX3c1nW9shhGGaJU9yybGVXviBpCF/Q8UejU+ eFNsQQjY3dGT3TqOEfaUxdjs4d5emNNr2H7sfRy9ZKrt/eWK5FCoGzVIyuqAyFWMzd 2/BW8zW0PlZPg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 050CC18006C for ; Sun, 13 Jul 2025 11:09:50 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, SPF_HELO_NONE,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 avril.gn2.hosting (avril.gn2.hosting [84.19.162.247]) (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 ; Sun, 13 Jul 2025 11:09:49 +0000 (UTC) Received: from avril.gn2.hosting (localhost [127.0.0.1]) by avril.gn2.hosting (Postfix) with ESMTP id 0885F1C40C1D; Sun, 13 Jul 2025 13:11:36 +0200 (CEST) Received: from smtpclient.apple (unknown [111.68.29.103]) by avril.gn2.hosting (Postfix) with ESMTPSA id E7E4B1C4082C; Sun, 13 Jul 2025 13:11:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nicksdot.dev; s=default; t=1752405095; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Ey7UtCcngZ2sZZy6yYs6KQyFr7IsVi4rPwc/IZYIUIQ=; b=3JJYc6Qg7x/CpWMNO9I29TdKV4rkyPeGljhmRYZ3ihMRAsTa8YIzqgreM/Mt7gXYJZk/u/ 5qFrFWoRj+JUeeoRwUCOtyCe/eJv3oDCCREOTfj9E/JPgpbMExSN+iGyEGHzqcZQSihbny WIlkz32LTHW5tGsNgTEHZXZx2rCpbKQQZqBDT7Z7AvYcc6ZQqlJFvQ1OfIJHXIYqtCfZUJ mO5av+s+r5BotU0o0vsO0MYpxPW2BjrFk6SwSacjPFxxDEtPBaL3N2HDY8KnWO5MFmpuqv JqAxD4icFeitusGzUGspBnYM3SlkxmwELLrhxNF0eFcJOh/SrULN9+cB2TpZ/w== Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_40142368-60E0-4934-A2B3-AB44906DCE0E" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Re: [PHP-DEV] RFC: Records Date: Sun, 13 Jul 2025 18:11:16 +0700 In-Reply-To: Cc: internals@lists.php.net To: Rob Landers References: X-Mailer: Apple Mail (2.3826.600.51.1.1) From: php@nicksdot.dev (Nick) --Apple-Mail=_40142368-60E0-4934-A2B3-AB44906DCE0E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > 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://wiki.php.net/rfc/records! >=20 > 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 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 for = every record. This allows you to get a new record similar to a given = one, 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, = language 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 discussion up here first. Love it or hate it, I'd like to hear your = thoughts. >=20 > =E2=80=94 Rob Hey Rob, You asked somewhere for feedback on the syntax conflict.=20 I would like to propose `Planet::(=E2=80=98earth=E2=80=99)`. The double-colon is what we are already used to for factory methods. Since you called the inline-constructor a =E2=80=9Cfactory function=E2=80=9D= in the RFC, I feel it would be a good fit.=20 Currently, this is a syntax error. Cheers, Nick= --Apple-Mail=_40142368-60E0-4934-A2B3-AB44906DCE0E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On 17. Nov = 2024, at 06:14, Rob Landers <rob@bottled.codes> wrote:

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 same 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 & = 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 methods (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 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, language 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 discussion up here first. Love it or hate it, I'd like = to hear your thoughts.

=E2=80=94 = Rob

Hey = Rob,

You asked somewhere for feedback on the = syntax conflict. 

I would like to propose = `Planet::(=E2=80=98earth=E2=80=99)`.

The = double-colon is what we are already used to for factory = methods.
Since you called the inline-constructor a =E2=80=9Cfact= ory function=E2=80=9D in the RFC, I feel it would be a good = fit. 

Currently, this is a syntax = error.

Cheers,
Nick
<= /body>= --Apple-Mail=_40142368-60E0-4934-A2B3-AB44906DCE0E--