>
> If the answer to that is "well don't do that", then what's the
> alternative?  PHP offers no other syntax for evolvable immutable objects
> than private properties with Wither methods.  Making Wither methods harder
> makes evolvable immutable objects harder.  Unless there's some entirely
> different approach I am not aware of to achieve the same goal, in which
> case please share. :-)
>

For transparency purposes: the idea I presented during the discussion of
"write-once" properties was
to make the following syntax (or a similar one) possible in order to make
cloning of these properties possible:
> $self = clone $this with {property1: "foo", ...};
It would clone the object and in the same time change the listed properties
(no matter if they have the "write-once"
flag). It would also take visibility rules into account, so a private
property could only be modified in the private scope.

I think this idea would address your concerns, although I haven't received
any feedback about it yet,
so I'm not sure if it has any gotchas/edge cases that would make it or its
implementation infeasible.

Máté

Reply via email to