Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115209 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13414 invoked from network); 29 Jun 2021 13:10:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jun 2021 13:10:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 28E041804F3 for ; Tue, 29 Jun 2021 06:30:19 -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=-1.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (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 06:30:18 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 699E75101324 for ; Tue, 29 Jun 2021 13:30:16 +0000 (UTC) To: internals@lists.php.net References: <24af2d01-4f6c-4389-a35a-dab50c0b5e66@www.fastmail.com> Message-ID: Date: Tue, 29 Jun 2021 15:30:15 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] Re: [RFC] Readonly properties From: pierre-php@processus.org (Pierre) Le 29/06/2021 à 15:08, Nikita Popov a écrit : > Well, it's a nifty hack :) I don't think this is the solution we want to > encourage though. It requires you pass extra information through a > side-channel -- I think I'd rather not use readonly than write that code. > > Continuing along the same line, one could extend that to "clone with > argument" and do something like this: > > public function __clone(self $original, array $replacements = []) { > foreach ($original as $k => $v) { > $this->$k = $replacements[$k] ?? $original->$k; > } > } > > and then do "clone $this(['bar' => $bar])". > > In any case, I don't want to include changes to cloning in this proposal -- > the topic is related, but also orthogonal to readonly properties. > Unfortunately, it will not be possible to get cloning changes into PHP 8.1 > anymore, due to feature freeze. > > It's okay to vote against this if cloning is a deal breaker. In that case > I'll probably either work on cloning before re-proposing this, or pivot to > asymmetric visibility -- it's not my first preference, but it may be the > more pragmatic choice. Cloning is definitely the weak point of this > proposal. > > Regards, > Nikita Hello, I agree that the "clone with" feature, no matter how the syntax will end up being, will become vital as soon as readonly properties will be there for many people. Nevertheless, I also agree with you, both can be done at different times, and even if it will block _some_ usages of readonly properties, readonly properties as you propose remain a must-have (in my opinion) even without the "clone with". I'd be pleased to use them an write really immutable objects, even if for cloning I need to do new Foo($otherFoo->prop1, $otherFoo->prop2), that's still a huge win in my opinion. I can't vote, but I can't say nothing if people want to block this RFC for having the clone with at the same, whereas it could be in a RFC of its own, and readonly properties are still a huge feature on its own, even without "clone with" support. That's a very wrong reason to say no in my opinion: on the contrary, having readonly properties being accepted and implemented as-is will be a very persuasive argument in favor of the future "clone with" RFC that may emerge following this one. -- Pierre