Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127374 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 E0A121A00BC for ; Thu, 15 May 2025 11:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747310070; bh=GUVxRU0BWzlwHg/+uuiaehj/NNyIRRGHhD3LWkw+FwU=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=f4z+8H6Izy3jTWb7SfkJXfNBT5wGLzlgIh/cEd2HPRcmsw5WvRLh0LEi6pRvGU02w QVhpsF61Yckv0HW7W3VCTU3C54dUhxqDaCA5DDwVx01nm6MB4Djmed6iAq5ztCT3yq KdaQnvK8SQod8MLSx4GN2fmAVgS73wK3Nn5irNfMLffauMqFzFXWdTIFATanH4sJLM T8emAm1/jgI6T0sK0ybzNLObz/YrgkqCuwSG7AMVuGOl7DFu5F/xEYwNNaWqrA+Ceb ZhbvIO/kDVvYXoZUvm91jSCrFoZfq3SATyP6mejxjTYMY0Mt5+kCIlmELwBbOP9Qzs dHMb2PbharPSw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C09CA180068 for ; Thu, 15 May 2025 11:54:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail1.25mail.st (mail1.25mail.st [206.123.115.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 15 May 2025 11:54:29 +0000 (UTC) Received: from smtpclient.apple (unknown [49.48.223.253]) by mail1.25mail.st (Postfix) with ESMTPSA id A515A6034F; Thu, 15 May 2025 11:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=koalephant.com; s=25mailst; t=1747310199; bh=GUVxRU0BWzlwHg/+uuiaehj/NNyIRRGHhD3LWkw+FwU=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=SOMqUb7NuNS7O+bQ3AmX2/5ENKRNLTYJ7vGRraxqK/ouuP/UaG2ncVPR7f/Tvatb+ Gnpmx2NLEMl8RJiQxe6ImocBNeN4Pf6Jv2GjVhJ8cvEn1dAKQpZzm1O6Cx0OKbBpf0 2+g6nINe1T2cFAeya0DCp3cIKm3lFy2tVrVEWGNNimdrcXvjkvkhjY+D09x1zzp7k9 HSdNHt8QBtR5KJEVyscSG6ksI73IURMRyLJXCg120DCOZsLQLnZyvieHMoUwtA4gQZ XpOKQgK74xq5P0PpUjyDh+Yrk2oGin3j5IL8zzYRWgthfYLXVhzzB1+PjkIjc4dXT3 03+OKMy6mmOXw== Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC] Clone with v2 Date: Thu, 15 May 2025 18:56:15 +0700 Message-ID: <266FA35A-15B0-435E-BBFE-1C6926EB0B7E@koalephant.com> References: Cc: Volker Dusch , Matthew Weier O'Phinney , php internals , =?utf-8?Q?Tim_D=C3=BCsterhus?= In-Reply-To: To: Andreas Hennings X-Mailer: iPhone Mail (22E252) From: php-lists@koalephant.com (Stephen Reay) > On 15 May 2025, at 16:44, Andreas Hennings wrote: >=20 > =EF=BB=BFOn Thu, 15 May 2025 at 08:24, Stephen Reay wrote: > [..] >>=20 >>=20 >> I may be missing something here.. >>=20 >> So far the issues are "how do we deal with a parameter for the actual obj= ect, vs new properties to apply", "should __clone be called before or after= the changes" and "this won't allow regular readonly properties to be modifi= ed". >>=20 >> Isn't the previous suggestion of passing the new property arguments direc= tly to the __clone method the obvious solution to all three problems? >=20 > What exactly should happen then? > Would the __clone() method be responsible for assigning those properties? > Or does the __clone() method get the chance to alter the values before > they are assigned? > (this would mean they have to be passed by reference) > I think this last option is the best, because the values in the array > can be changed without any readonly constraints. >=20 > Another option I was thinking of would be to call __clone() after the > changes are applied, and pass both the original object and the array > of changes as first parameter. > But I think this is a dead end. >=20 > -- Andreas >=20 >>=20 >> There's no potential for a conflicting property name, the developer can u= se the new property values in the order they see fit relative to the logic i= n the __clone call, and it's inherently in scope to write to any (unlocked d= uring __clone) readonly properties. >>=20 >>=20 >>=20 >> Cheers >>=20 >> Stephen >>=20 >>=20 >>=20 >=20 I would suggest that the __clone method should be directly responsible for m= aking any changes, just as it is now when it comes to deep cloning or resett= ing values. Yes I realise it means developers need to then opt in and provide the functi= onality to support `clone $foo with(bar: "baz")` or whatever syntax is used.= =20 If the properties are public properties, there's nothing stopping someone wr= iting their own clone_with() in userland now; If someone is using readonly p= roperties I'd suggest they want to specifically manage updates to those prop= erties themselves anyway.=20 Additionally it means "clone with" would be usable for non-public properties= at the discretion of the developer writing their code.=20 The mental model is also very clear with this: copy the object in memory, an= d then call __clone(), with the arguments passed to the clone action - which= may be none in the case of code that doesn't accept any clone arguments. T= he only change from the current model is that it *may* be passing arguments.= =20 Cheers Stephen=20