Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128091 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 C55BF1A00BC for ; Thu, 17 Jul 2025 04:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752726716; bh=9SynFnKXOFSG7/xTQJ2PBcgTaVCkU4UocABh+nTpibA=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=DhHJgsSYVJtV6pRLpnDIhbhLt8r02gIf69X5FvHHw8hapvwB08riu/BXBlDbUeAUe qOUAlPao7t1RfWgCIQrPgEQl0pTxuPNY1v/RI8y2h6qIQU/EUTNv7jtCtyMOu10cQU G6J2+fAef9YFHvMd1/GDbEcFWflQgVB2hvBp6ovBYy+M6tdoq0/faEOmt7n5EtLk+5 0/kGqK+KH5IkWbEjg01Hl++Z+iLAuiFR9v96qZDyVdkDPzU+f/knK8qz+EnBSzJQaz jTp9wD+tDIkPfM/C+X1hgv8msLwPjQnA0Bazesh3OnAwiCCN71Rc+l+gp8s/3SAulB BQmqZuZjgnI9Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C0067180039 for ; Thu, 17 Jul 2025 04:31:54 +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.2 required=5.0 tests=BAYES_20,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 ; Thu, 17 Jul 2025 04:31:53 +0000 (UTC) Received: from avril.gn2.hosting (localhost [127.0.0.1]) by avril.gn2.hosting (Postfix) with ESMTP id 29AE61C40C1D; Thu, 17 Jul 2025 06:33:38 +0200 (CEST) Received: from smtpclient.apple (unknown [36.72.215.169]) by avril.gn2.hosting (Postfix) with ESMTPSA id 070661C4075E; Thu, 17 Jul 2025 06:33:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nicksdot.dev; s=default; t=1752726814; 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=/Pf6lQ/0jK5hwUAOzu7HKSphVx+IktEtK6DXSxXsy1Q=; b=t+qgi+3b31iu03FZTVW72AESg2yRq03XeY3Dss5DMpyF7TYXz28zkfBI3BfRKLIz5qE8n3 hqREuwe0DBHcAlKRhjupHfAAuXeHD6POVHO/itXetrjvsxsudeG7AsaJ7do81BGGrfMCvw OCft6w2UP6zfQ6RyhAtCzcP7IWJ5kJ2sVa+QKl7PQodAli88Cr1kq0+C7Ni68ZmxdFOXz3 inpteXT6/Sfb/Lx4nFapM9vI/Xa+IpDWC1ll6YYevaugvPmNitbEw1Q9gDLSgOZTl72hwC 3Q7njDDRgIWhRnq0sjpzR/DIfNoD57K311ijiW1Gtbevob7FPOIqn2lmsedzng== Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_DCBEC7B0-FDBE-4B6C-9A3A-FAE63496AEEB" 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: Thu, 17 Jul 2025 11:33:12 +0700 In-Reply-To: Cc: Dmitry Derepko , internals@lists.php.net To: Rob Landers References: <0D6532F3-6E95-48B9-B394-E9CC1EC00B56@gmail.com> X-Mailer: Apple Mail (2.3826.600.51.1.1) From: php@nicksdot.dev (Nick) --Apple-Mail=_DCBEC7B0-FDBE-4B6C-9A3A-FAE63496AEEB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 15. Jul 2025, at 01:22, Rob Landers wrote: >=20 >> 5. Inline constructor isn=E2=80=99t necessary and could be proposed = separately. I=E2=80=99ve thought recently about this feature >=20 > I will probably remove this, to be honest. It was for nesting records = inside classes or other records, but this feature was declined, so there = isn't really a need for it. Hey Rob, Personally, I was really excited to see inline constructors in the = proposal. And I would go even further than what you proposed. While you already work on something completely new, why not drop = `__construct` completely? Dreaming out loud=E2=80=A6 ```php record User(string $name, string $emailAddress) =3D> ( // init constructor start if (!is_valid_email($emailAddress)) { // doesn't require $this throw new InvalidArgumentException('Invalid email address'); } $this->id =3D hash('sha256', $emailAddress); $this->name =3D ucwords($name); // all properties are now immutable ) { // actual body with everything else public string $id; } ``` With that: - Both constructors would be kept together at the top; not an additional = constructor potentially after some properties and maybe methods. - An extra level of indentation is avoided because there is no = `__construct` around it. - Reading doesn=E2=80=99t required `$this` for `$name` and = `$emailAddress` because we are not in an argument-free traditional = constructor. I think the same about the proposed Struct RFC, fwiw. Both care not = classes.=20 So, why not make them more lean than classes, and feel clearly different = to classes? -- Cheers, Nick --Apple-Mail=_DCBEC7B0-FDBE-4B6C-9A3A-FAE63496AEEB Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On 15. Jul = 2025, at 01:22, Rob Landers <rob@bottled.codes> = wrote:

5. Inline constructor isn=E2=80=99= t necessary and could be proposed separately. I=E2=80=99ve thought = recently about this feature

I will = probably remove this, to be honest. It was for nesting records inside = classes or other records, but this feature was declined, so there isn't = really a need for it.

Hey = Rob,

Personally, I was really excited to see = inline constructors in the proposal. And I would go even further than = what you proposed.
While you already work on something = completely new, why not drop `__construct` = completely?

Dreaming out = loud=E2=80=A6

```php
record User(string =
$name, string =
$emailAddress) =3D> =
(
    // init =
constructor start
if (!is_valid_email($emailAddress)) { // doesn't require $this
throw new InvalidArgumentException('Invalid email address');
= }

$this->id = =3D hash('sha256', = $emailAddress);
$this->name = =3D ucwords($name);
    // all properties are now =
immutable
) {
// actual body with everything else
public string = $id;
}

```

With = that:
- = Both constructors would be kept together at the top; not an additional = constructor potentially after some properties and maybe = methods.
- An extra level of indentation is avoided because there is = no `__construct` around it.
- Reading doesn=E2=80=99t required `$this` for = `$name` and `$emailAddress` because we are not in an argument-free = traditional constructor.

I think the same about the proposed Struct RFC, = fwiw. Both care not classes. 
So, why not make them more lean than = classes, and feel clearly different to classes?

--

Cheers,
Nick

<= /div>





=





= --Apple-Mail=_DCBEC7B0-FDBE-4B6C-9A3A-FAE63496AEEB--