Re: Improving PHP's Object Egonomics: A broad analysis

From: Date: Tue, 24 Mar 2020 15:11:35 +0000
Subject: Re: Improving PHP's Object Egonomics: A broad analysis
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-109277@lists.php.net to get a copy of this message
> > 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é

« previous php.internals (#109277) next »