Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127375 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 09A481A00BC for ; Thu, 15 May 2025 12:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747311182; bh=I0VxIHwl/G89+YBIsXzXZuV0lfw4qPqdzX0YZ/XV2Zw=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=O+o6n6pk5k4oP2/kaxn0E7zJV1Zv+HeeDEjwrpTSHSL5ohFizJ6NC2EVOvVaTOoyj 7i669/dye5/o4OFARNnhbce8UcNQS6M1UVdcse7Oap9KHpA2orz4D+2zrVXNICyOnH 76TEn8If2OjWohPITsZDimiHhfmPOt8VWzhzD+5mD54W2qu+Q0uGXNSVcdwjxC548w vvtltmTbeJf4Pa5Hwbjn1rpVmHgj/qI+jB2uOnuuCDfR0S2LrO1JaVHWJ46ZxiWdJr DfFL+w0SSgd7Ei6y+Vb24s5XQJkPTZB4Zc//ZC7duaceOVRxQe6PDa/f6zLfY2Srbt qkgbIZSBwSsLw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3981D180387 for ; Thu, 15 May 2025 12:13:00 +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.9 required=5.0 tests=BAYES_40,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.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b2-smtp.messagingengine.com (fhigh-b2-smtp.messagingengine.com [202.12.124.153]) (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, 15 May 2025 12:12:59 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id EC9E82540157; Thu, 15 May 2025 08:15:09 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-05.internal (MEProxy); Thu, 15 May 2025 08:15:10 -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=fm1; t=1747311309; x= 1747397709; bh=fMYJo59JHHf14/rs/zEVhR9y1J1GTE48nmATqnHhp/4=; b=M SbRXuQBC42C1A9OwTFWYczE5b4N9fYfW/kZ+oGMt6gsq/qTSqPspHi1wvTJBoyfe wlPAS98bu8RCD7fyjjAKifK8+1CG3bbIiZ4EamRfIKYz2b14FCwsZ4W4rsmrB0Ba FAvUsKbHeGZDbQ5AXBXzmIsyIiGgsUakqC9VkUObfTV704duq+8l76gOjSTxMY4o VmWFP1EjMIOpeDZnNYfTD8VGFWFQGWEfHRFv8PR0P99hvEQA9nj7xszUiU29eo7q XoCZ4zqw2bTD9oBmb3ulcqYcVyxmFVUfRyc18hBekYJbDUVXBrr/OKG6TlNYZh4C GnizE2ZxgduS0puy69GfA== 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=fm3; t= 1747311309; x=1747397709; bh=fMYJo59JHHf14/rs/zEVhR9y1J1GTE48nmA TqnHhp/4=; b=ujy/emNX3WNiab2gBXgdepaApEpPTR9lhCZfoPCK88VSoNK1GLt gmbgc7JnWtBt1UY3DzxdDcW9NJPunAJGOGj2gLQSJBd8uLg2T3WsnG8Xxc6uKf5H jS+4klvtyOh5sioADwY4UMrgrnMGQmTh64DBoiBmXU71Ityw4cgOsfghVllIM3pF 0M+bclCc/YuClYlNPolkfYNgkCJVD1fAJS1Z9oxPv1oiz+BKFSeU0VF28DY9vrch Hg69CluVP4orIgArJZUD53DaLH9HAPcKrOhyXIanM8WXIqLCpyxG2k01C57vcSzJ XgKl062IcEiz7c0hzEvJEmyIYWxI6NQ9oFQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeftdelkeegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerredt jeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurd gtohguvghsqeenucggtffrrghtthgvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfh feekjefflefgvedvkeduteejjedttdenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgt phhtthhopeeipdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehtihhmsegsrghsth gvlhhsthhurdgsvgdprhgtphhtthhopegrnhgurhgvrghsseguqhigthgvtghhrdhnvght pdhrtghpthhtohepmhifvghivghrohhphhhinhhnvgihsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepphhhphdqlhhishhtsheskhhorghlvghphhgrnhhtrdgtohhmpdhrtghpthht ohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvthdprhgtphhtthhopehvoh hlkhgvrhesthhiuggvfigrhihsqdhgmhgshhdrtghomh X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 4BC5F302005E; Thu, 15 May 2025 08:15:09 -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: Ta3b79d818733aba6 Date: Thu, 15 May 2025 14:14:48 +0200 To: "Stephen Reay" , "Andreas Hennings" Cc: "Volker Dusch" , "Matthew Weier O'Phinney" , "php internals" , =?UTF-8?Q?Tim_D=C3=BCsterhus?= Message-ID: <74fde04e-1cbf-423c-8b50-7d7eb156a056@app.fastmail.com> In-Reply-To: <266FA35A-15B0-435E-BBFE-1C6926EB0B7E@koalephant.com> References: <266FA35A-15B0-435E-BBFE-1C6926EB0B7E@koalephant.com> Subject: Re: [PHP-DEV] [RFC] Clone with v2 Content-Type: multipart/alternative; boundary=a1c3b7ef47ff49c7835b54d079446da8 From: rob@bottled.codes ("Rob Landers") --a1c3b7ef47ff49c7835b54d079446da8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, May 15, 2025, at 13:56, Stephen Reay wrote: >=20 >=20 >=20 > > On 15 May 2025, at 16:44, Andreas Hennings wro= te: > >=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 actu= al object, vs new properties to apply", "should __clone be called befor= e or after the changes" and "this won't allow regular readonly propertie= s to be modified". > >>=20 > >> Isn't the previous suggestion of passing the new property arguments= directly to the __clone method the obvious solution to all three proble= ms? > >=20 > > What exactly should happen then? > > Would the __clone() method be responsible for assigning those proper= ties? > > Or does the __clone() method get the chance to alter the values befo= re > > 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 use the new property values in the order they see fit relative to t= he logic in the __clone call, and it's inherently in scope to write to a= ny (unlocked during __clone) readonly properties. > >>=20 > >>=20 > >>=20 > >> Cheers > >>=20 > >> Stephen > >>=20 > >>=20 > >>=20 > >=20 >=20 > I would suggest that the __clone method should be directly responsible= for making any changes, just as it is now when it comes to deep cloning= or resetting values. >=20 > Yes I realise it means developers need to then opt in and provide the = functionality to support `clone $foo with(bar: "baz")` or whatever synta= x is used.=20 >=20 > If the properties are public properties, there's nothing stopping some= one writing their own clone_with() in userland now; If someone is using= readonly properties I'd suggest they want to specifically manage update= s to those properties themselves anyway.=20 >=20 > Additionally it means "clone with" would be usable for non-public prop= erties at the discretion of the developer writing their code.=20 >=20 > The mental model is also very clear with this: copy the object in memo= ry, and then call __clone(), with the arguments passed to the clone acti= on - which may be none in the case of code that doesn't accept any clone= arguments. The only change from the current model is that it *may* be = passing arguments.=20 >=20 > Cheers >=20 > Stephen=20 >=20 When I was working on Records, one of the important things was the abili= ty to "hook into" the update that was about to happen. For example, if y= ou have a Money type, you'd want to be able to ensure it cannot be negat= ive when updating via `with()`. This is super important for ensuring con= straints are met during the clone. =E2=80=94 Rob --a1c3b7ef47ff49c7835b54d079446da8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, May = 15, 2025, at 13:56, Stephen Reay wrote:



&g= t; On 15 May 2025, at 16:44, Andreas Hennings <andreas@dqxtech.net> wrote:
> =
> =EF=BB=BFOn Thu, 15 May 2025 at 08:24, Stephen Reay <= php-lists@koalephant.com= > wrote:
> [..]
>> 
>&= gt; 
>> I may be missing something here..
>> 
>> So far the issues are "how do we deal= with a parameter for the actual object, vs new properties to apply",&nb= sp; "should __clone be called before or after the changes" and "this won= 't allow regular readonly properties to be modified".
>>=  
>> Isn't the previous suggestion of passing the n= ew property arguments directly to the __clone method the obvious solutio= n to all three problems?
> What exactl= y should happen then?
> Would the __clone() method be respo= nsible for assigning those properties?
> Or does the __clon= e() 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 reado= nly constraints.
> Another option I wa= s thinking of would be to call __clone() after the
> change= s are applied, and pass both the original object and the array
> of changes as first parameter.
> But I think this is = a dead end.
> -- Andreas
>= ; 
>> 
>> There's no potential= for a conflicting property name, the developer can use the new property= values in the order they see fit relative to the logic in the __clone c= all, and it's inherently in scope to write to any (unlocked during __clo= ne) readonly properties.
>> 
>>&nbs= p;
>> 
>> Cheers
>>=  
>> Stephen
>> 
>= ;> 
>> 

=
I would suggest that the __clone method should be directly re= sponsible for making any changes, just as it is now when it comes to dee= p cloning or resetting values.

Yes I realise it= means developers need to then opt in and provide the functionality to s= upport `clone $foo with(bar: "baz")` or whatever syntax is used. 

If the properties are public properties, there's= nothing stopping someone writing their own clone_with() in userland now= ;  If someone is using readonly properties I'd suggest they want to= specifically manage updates to those properties themselves anyway. = ;

Additionally it means "clone with" would be u= sable for non-public properties at the discretion of the developer writi= ng their code. 

The mental model is also v= ery clear with this: copy the object in memory, and then call __clone(),= with the arguments passed to the clone action - which may be none in th= e case of code that doesn't accept any clone arguments.  The only c= hange from the current model is that it *may* be passing arguments. = ;

Cheers

Stephen =


When I was working= on Records, one of the important things was the ability to "hook into" = the update that was about to happen. For example, if you have a Money ty= pe, you'd want to be able to ensure it cannot be negative when updating = via `with()`. This is super important for ensuring constraints are met d= uring the clone.

=E2=80=94 = Rob
--a1c3b7ef47ff49c7835b54d079446da8--