Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115210 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15546 invoked from network); 29 Jun 2021 13:25:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jun 2021 13:25:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 90B011804B3 for ; Tue, 29 Jun 2021 06:45:04 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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:45:03 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 1619F32002D8 for ; Tue, 29 Jun 2021 09:45:02 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Tue, 29 Jun 2021 09:45:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Xg7G/s oo8esUjIhsJsIhTtwFbxbofV+sjV9HWh5fSIs=; b=rEdIdXJLaTbLvpOHDn8LET PA1kdEoifvGk8RIqUDvBTYx2q07tcTDGymirBZKTFmjOelJmKSLfvvcAD8xeZ46X ba6IxrO/VC1a5SxxqVtJjWaI7ev+hsxCNNTQ+APtzh+ExG/mr5kUgD2UpudOpqoa AdapJzcJ/79AlIiG0iz5RH+4Qsbs4NSzhmg2Ap1zsz8+uZth2SXfUlgq4itELt8Q ZV+3PA5lH/f77ZQDFIqdpPmwoLXQ4W8RPFhCZ/SuZY7OEsqiZ3HWDr5/1jMkbTgZ uO9k5DmoxvImy3yeIV1EuzMMAtJjQ3Y66QHIBL4B1iJ2Brmqs68ABV6e8dcKClSw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeitddgfeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 246F9AC0073; Tue, 29 Jun 2021 09:45:01 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-530-gd0c265785f-fm-20210616.002-gd0c26578 Mime-Version: 1.0 Message-ID: In-Reply-To: References: <24af2d01-4f6c-4389-a35a-dab50c0b5e66@www.fastmail.com> Date: Tue, 29 Jun 2021 08:44:39 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Re: [RFC] Readonly properties From: larry@garfieldtech.com ("Larry Garfield") On Tue, Jun 29, 2021, at 8:08 AM, Nikita Popov wrote: > > You might not like the boilerplate, but that just works. > > > > Can this be considered Nikita? > > > > 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 I already went through the clone-arguments mental exercise in my earlier analysis, and the code it produces is totally disgusting. :-) clone-with is a considerably better approach if you're starting from readonly. (It's also better if you start from asymmetric visibility, although that version needs a clone-help feature far less.) --Larry Garfield