🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by "Rob Landers" Thu, 15 May 2025 12:14
Re: [PHP-DEV] [RFC] Clone with v2
#1
Author: "Rob Landers"
Date: Thu, 15 May 2025 12:14
158 lines
14235 bytes
--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 <andreas@dqxtech.net> wro=
te:
> >=20
> > =EF=BB=BFOn Thu, 15 May 2025 at 08:24, Stephen Reay <php-lists@koale=
phant.com> 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

<!DOCTYPE html><html><head><title></title></head><body><div>On Thu, May =
15, 2025, at 13:56, Stephen Reay wrote:</div><blockquote type=3D"cite" i=
d=3D"qt" style=3D""><div><br></div><div><br></div><div><br></div><div>&g=
t; On 15 May 2025, at 16:44, Andreas Hennings &lt;<a href=3D"mailto:andr=
eas@dqxtech.net">andreas@dqxtech.net</a>&gt; wrote:</div><div>&gt;&nbsp;=
</div><div>&gt; =EF=BB=BFOn Thu, 15 May 2025 at 08:24, Stephen Reay &lt;=
<a href=3D"mailto:php-lists@koalephant.com">php-lists@koalephant.com</a>=
&gt; wrote:</div><div>&gt; [..]</div><div>&gt;&gt;&nbsp;</div><div>&gt;&=
gt;&nbsp;</div><div>&gt;&gt; I may be missing something here..</div><div=
>&gt;&gt;&nbsp;</div><div>&gt;&gt; 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".</div><div>&gt;&gt;=
&nbsp;</div><div>&gt;&gt; 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?</div><div>&gt;&nbsp;</div><div>&gt; What exactl=
y should happen then?</div><div>&gt; Would the __clone() method be respo=
nsible for assigning those properties?</div><div>&gt; Or does the __clon=
e() method get the chance to alter the values before</div><div>&gt; they=
 are assigned?</div><div>&gt; (this would mean they have to be passed by=
 reference)</div><div>&gt; I think this last option is the best, because=
 the values in the array</div><div>&gt; can be changed without any reado=
nly constraints.</div><div>&gt;&nbsp;</div><div>&gt; Another option I wa=
s thinking of would be to call __clone() after the</div><div>&gt; change=
s are applied, and pass both the original object and the array</div><div=
>&gt; of changes as first parameter.</div><div>&gt; But I think this is =
a dead end.</div><div>&gt;&nbsp;</div><div>&gt; -- Andreas</div><div>&gt=
;&nbsp;</div><div>&gt;&gt;&nbsp;</div><div>&gt;&gt; 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.</div><div>&gt;&gt;&nbsp;</div><div>&gt;&gt;&nbs=
p;</div><div>&gt;&gt;&nbsp;</div><div>&gt;&gt; Cheers</div><div>&gt;&gt;=
&nbsp;</div><div>&gt;&gt; Stephen</div><div>&gt;&gt;&nbsp;</div><div>&gt=
;&gt;&nbsp;</div><div>&gt;&gt;&nbsp;</div><div>&gt;&nbsp;</div><div><br>=
</div><div>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.</div><div><br></div><div>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.&nbsp;</=
div><div><br></div><div>If the properties are public properties, there's=
 nothing stopping someone writing their own clone_with() in userland now=
;&nbsp; If someone is using readonly properties I'd suggest they want to=
 specifically manage updates to those properties themselves anyway.&nbsp=
;</div><div><br></div><div>Additionally it means "clone with" would be u=
sable for non-public properties at the discretion of the developer writi=
ng their code.&nbsp;</div><div><br></div><div>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.&nbsp; The only c=
hange from the current model is that it *may* be passing arguments.&nbsp=
;</div><div><br></div><div>Cheers</div><div><br></div><div>Stephen&nbsp;=
</div><div><br></div></blockquote><div><br></div><div>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.</div><div><br></div><div id=3D"sig121229152">=E2=80=94 =
Rob</div></body></html>
--a1c3b7ef47ff49c7835b54d079446da8--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads