Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128092 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 BA0F11A00BC for ; Thu, 17 Jul 2025 06:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752735078; bh=9YgfqhhMe+QPmYZtuLUMYL735uzeBri5ALWsvsh7ovA=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=ipbIo2oPzcMGHRqzb4T2elEIaGM8BAFcdlm60jSzvrvy49JOb4Qo13CdsqMRWXdCE Ni3/7+tPtfqm7uoWTHM5yCJBJZQvieSbm8T+OozrxaMRpdZx018HhhmjTqtObCamTR /30ro0OFcCsD+j3nmkpqwFwlOCfqqtcxvOj6GL093gkLBAjMz6CfBtb4HqDMAEiqNm z0FKpmJFXYentN1Ac/WcQ5r7h0LUfX9rJAA6Bh9L44KrzD0m/oWp8A19O9PNAXBpPE mRT5242L1O3WhNnkskqE1HlP0OHsye6rwJRliHqmdhko9spqNtgVpARmmJrPw0307I VOxY8ncls/0lw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 565D9180054 for ; Thu, 17 Jul 2025 06:51:17 +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=-2.8 required=5.0 tests=BAYES_00,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.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-b6-smtp.messagingengine.com (fout-b6-smtp.messagingengine.com [202.12.124.149]) (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 06:51:16 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id AE0211D000CC; Thu, 17 Jul 2025 02:53:02 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Thu, 17 Jul 2025 02:53:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1752735182; x= 1752821582; bh=tHU2Jli8o0z10phzNsg8eYhdX0AGceTcClCzEWLbm04=; b=E T6WXOlVjgJwxYhtV2oVESi0Zfo1+v9IRWs4XVW+IirnqKa/6c86lZsXSQitP9wtM D5eMJisVWO7M7127gxU301WBKSZ1gVR8O+X+Ln/rmk30WtpMxVZEl7ym5vhIYRGv LrqLfJgeRicWx/cmw+D9Bb7qQJlkWzubeqV12ZV5KpNKFyKNUTRKZlEq2hZ7N2Bf uKeCNid2L1jPH4bBBB/5OmTV4WbKdRpe/xl5YKu6063TZA3f3pagDHx6yyg1zrWd gcI4C374CHUcnKmx6AEQp6zRu3hKL42BICXPYLXaZYX1CIZyawCliTQAax8eJ2lG ZydAvXoKB//rmc8Qel4Og== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1752735182; x=1752821582; bh=tHU2Jli8o0z10phzNsg8eYhdX0AGceTcClC zEWLbm04=; b=iFL3l1pywVc1e65qhx5c0BD47XkHdgAymd8LCR9iDN/ibvRxmio 6TTVU8Od5/mAkvCmBdTnOsWy/1Ek1UWpt623u7/S5zuZVpDB+oiwK6mpQRQxZyd7 Oyl50hy8sVAxLhkLU7miiN7wQSJIksfKG/KNYYVOL+Oc60UUlq2X1iQTCzmfqaUj dVFG8QSObSt7dtB0Uv/YnvOHRwpUEiDAnivHTqD4Q51m3irHUpBlFIeVeCiIc3vd AhcgiQldZYEzvamq6cQ4ECRaFPhcd/KRLHoePEy1b3hWz6aThR+pOnglNt1dPqtB pDaMlbrorLbvzBwyng2RmcobUl4TR/UTBVA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdehleeludcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerre dtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggu rdgtohguvghsqeenucggtffrrghtthgvrhhnpeeiueethedvvdefjefhgfeiheelheehtd fhfeekjefflefgvedvkeduteejjedttdenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprh gtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehnihgtohhlrghs rdhgrhgvkhgrshdophhhphesghhmrghilhdrtghomhdprhgtphhtthhopeigvghpohiiii gusehgmhgrihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdr phhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 3940F1820074; Thu, 17 Jul 2025 02:53:02 -0400 (EDT) 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 X-ThreadId: Ta3f42e4d0ede798b Date: Thu, 17 Jul 2025 08:52:34 +0200 To: "Nicolas Grekas" Cc: "Dmitry Derepko" , internals@lists.php.net Message-ID: <21a13437-9104-4950-a2dd-13b9cf1d66cf@app.fastmail.com> In-Reply-To: References: <0D6532F3-6E95-48B9-B394-E9CC1EC00B56@gmail.com> Subject: Re: [PHP-DEV] RFC: Records Content-Type: multipart/alternative; boundary=cc4d1520f5664594a79871409c308489 From: rob@bottled.codes ("Rob Landers") --cc4d1520f5664594a79871409c308489 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Jul 15, 2025, at 19:05, Nicolas Grekas wrote: > Not sure it's really a contribution to the discussion but in case you = missed it, you can make public properties "public(set)": >=20 > final readonly class Response { > public function __construct( > public public(set) int $statusCode, > public public(set) string $reasonPhrase, > // ... > ) { > if($this->statusCode >=3D 600) { > throw new LogicException(); > } > } > } >=20 > Then your example works. > That's ugly, but that doesn't have to stay that way. > And I'm now wondering why is that not the default? >=20 > Nicolas It "works" but it still results in an invalid state (statusCode >=3D 600= is never thrown). Previously, this kind of invalid object would only be= possible via reflection and skipping the constructor. Now, we have a co= py, without a copy-constructor to perform any validation or error checki= ng before the copy completes; so basically invalid objects are incredibl= y easy/accidental to be made, unless everyone starts changing all valida= tion to be done in getters/setters (which is not possible on readonly ob= jects) or by keeping things protected(set) and ensuring that only specif= ic functions set them... and probably make every readonly class final. =E2=80=94 Rob --cc4d1520f5664594a79871409c308489 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Tue, Jul = 15, 2025, at 19:05, Nicolas Grekas wrote:
Not sure it's really a contribution to th= e discussion but in case you missed it, you can make public properties "= public(set)":

final readonly class Respons= e {
    public function __construct(
 = ;       public public(set) int $statusCode,
&nb= sp;       public public(set) string $reasonPhrase,
<= div>        // ...
    ) {
=
        if($this->statusCode >=3D 600) {<= /div>
            throw new LogicExcep= tion();
        }
    = }
}

Then your example works.
That's ugly, but that doesn't have to stay that way.
A= nd I'm now wondering why is that not the default?

Nicolas
=
It "works" but it still results in an invalid state (stat= usCode >=3D 600 is never thrown). Previously, this kind of invalid ob= ject would only be possible via reflection and skipping the constructor.= Now, we have a copy, without a copy-constructor to perform any validati= on or error checking before the copy completes; so basically invalid obj= ects are incredibly easy/accidental to be made, unless everyone starts c= hanging all validation to be done in getters/setters (which is not possi= ble on readonly objects) or by keeping things protected(set) and ensurin= g that only specific functions set them... and probably make every reado= nly class final.

=E2=80= =94 Rob
--cc4d1520f5664594a79871409c308489--