Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115201 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74104 invoked from network); 29 Jun 2021 06:54:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jun 2021 06:54:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C9AE71804F3 for ; Tue, 29 Jun 2021 00:14:52 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 29 Jun 2021 00:14:52 -0700 (PDT) Received: by mail-ed1-f48.google.com with SMTP id df12so29876086edb.2 for ; Tue, 29 Jun 2021 00:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=43o3BkHc2QiJVX+1SMOwV/8bP14YVUze1ozxxDm5w+g=; b=m9nfQrmpdTLfKddnFY+4eCHQ5/7N1tWz3LgrwuRSJfVIYpV9T+X/q/NynhBCtJZtT5 rt8pkYcJ280LyoLemXeUAlFpIIt/zVxKovgzoycNjh+CgYz17Xj+FXOv83jREI+p/tcY qdjQpgZP5qzmi78QsC1DFgxf0ZXfX/vacrr9ePL3Wbb9n4ffnApDvAxUIyK6TUoHqHT5 ehd3Wy/SKSqiiNrqxlo2P0OMxGGNKaazobB6coi6l7ImYVXgJAJ3Hy5ekOQ24flDAM+0 EV9uiy31mLu+CEAomUN4KeFb5MEr4ASGfaU0JCfVj0htgA6xrHv/dB3j6EQQgz4/WHw+ fhAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=43o3BkHc2QiJVX+1SMOwV/8bP14YVUze1ozxxDm5w+g=; b=ifTk9D1RTg2DQVkv4sPBPA6ecpd0CzQKSuM9PIbuaAfjVfVkyDZDvhwjivnP1begE8 92foBJlTpR7dhYEVYYSwlwfnvm3cBAxAkNdJE5T4DMCjdHj5BB86dTqYrpVARdAeK+mx nDRG2ew4rgjY+Hg/VMrTFxVqIy2famMl0VS0anPl4ZH3Uv5hRxlmedRmDBrNiBf6cuQ4 PpZr8a25XtFA1CiOg32rR5c/Q/2qN5ThVYhoPUvZ9bXmWfGRsgRwyjvqQjNElwyXultU ZWGQzjX6QT48Y93fpfetYtEwq2iSHjM3M4balQ+szKds0F+ZjC7yccauE1amwUId3z/f gn2A== X-Gm-Message-State: AOAM531Ljb2k+QaJ3oYV8OlpJphp/YE7doiDrMxswrqgUdYhB5/PjGcE Gz7fiTIrwQuBGE/ALAXZYtzszFb4do0sJVrA+J0= X-Google-Smtp-Source: ABdhPJygLQr86ymAxH3ppNhsmUFT/BNP9Tc4BkKgA2/clsA8VQHUOr/Q+jkM3uNrRdI6p4Akj5vd98KzsCGrRAOIww4= X-Received: by 2002:a05:6402:111a:: with SMTP id u26mr37741745edv.260.1624950887817; Tue, 29 Jun 2021 00:14:47 -0700 (PDT) MIME-Version: 1.0 References: <24af2d01-4f6c-4389-a35a-dab50c0b5e66@www.fastmail.com> In-Reply-To: Date: Tue, 29 Jun 2021 09:14:33 +0200 Message-ID: To: Larry Garfield , Nikita Popov Cc: php internals Content-Type: multipart/alternative; boundary="0000000000007226b605c5e25cac" Subject: Re: [PHP-DEV] Re: [RFC] Readonly properties From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --0000000000007226b605c5e25cac Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > Le lun. 28 juin 2021 =C3=A0 18:22, Larry Garfield a >> =C3=A9crit : >> >>> On Mon, Jun 28, 2021, at 11:17 AM, Nicolas Grekas wrote: >>> > > > I'd like to open the discussion on readonly properties: >>> > > > https://wiki.php.net/rfc/readonly_properties_v2 >>> > > > >>> > > > This proposal is similar to the >>> > > > https://wiki.php.net/rfc/write_once_properties RFC that has been >>> > > declined >>> > > > previously. One significant difference is that the new RFC limits >>> the >>> > > scope >>> > > > of initializing assignments. I think a key mistake of the previou= s >>> RFC >>> > > was >>> > > > the confusing "write-once" framing, which is both technically >>> correct and >>> > > > quite irrelevant. >>> > > > >>> > > > Please see the rationale section ( >>> > > > https://wiki.php.net/rfc/readonly_properties_v2#rationale) for >>> how this >>> > > > proposal relates to other RFCs and alternatives. >>> > > > >>> > > >>> > > I plan to open voting on this RFC soon. I don't think there's >>> anything >>> > > technical left to address here, the discussion mostly comes down to >>> a value >>> > > judgement. I think everyone has made their position regarding that >>> clear... >>> > > >>> > >>> > Actually, we talked off the list about a way to possibly make this wo= rk >>> > with __clone(): >>> > >>> > We could allow __clone to have one argument, the object being cloned. >>> And >>> > when the signature declares this argument, then all readonly properti= es >>> > would be set as uninitialized on $this. >>> > >>> > A typical __clone function would look like this with readonly >>> properties: >>> > function __clone(object $original) >>> > { >>> > $this->readonlyProp =3D clone $original->readonlyProp; >>> > } >>> > >>> > That would turn my vote into a +1 if that could be made to work! >>> >>> That sounds like it would support deep cloning, but not with-er >>> methods. There's no way to provide a changed value. It also would mea= n a >>> lot of work on larger objects to transfer across all the properties. I >>> don't really see what this would add. >>> >> >> Can you elaborate about the lack of support for withers? Having some wor= k >> to do doesn't look like an issue to me, especially when there is no >> alternative to compare that too. >> > > I sent that too fast, I agree about withers... :) > I'm looking for a way to +1 that RFC... > Any other idea? > And I was too fast agreeing that my proposal to pass the original object as argument was incompatible with withers. I also think that not being compatible with deep cloning is a major issue. Past trivial cases, the use cases I can think of where I would use readonly require deep cloning. See eg the Symfony Request object where query params, headers, and a few others expose state as public objects. Here is some code that just works with them: class C { public readonly string $foo; public readonly string $bar; private $skipWhenCloning; public function withFoo($foo) { $this->skipWhenCloning =3D 'foo'; $clone =3D clone $this; $clone->foo =3D $foo; } public function withBar($bar) { $this->skipWhenCloning =3D 'bar'; $clone =3D clone $this; $clone->bar =3D $bar; } public function __clone(self $original) { foreach ($this as $k =3D> $v) { if ($k !=3D=3D $this->skipWhenCloning) { $this->$k =3D $original->$k; } } $this->skipWhenCloning =3D $original->skipWhenCloning =3D null; } } You might not like the boilerplate, but that just works. Can this be considered Nikita? --0000000000007226b605c5e25cac--