Re: [RFC][DISCUSSION] - Immutable classes and properties
| From: | Rowan Collins | Date: | Mon, 12 Dec 2016 14:14:26 +0000 |
| Subject: | Re: [RFC][DISCUSSION] - Immutable classes and properties | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-97365@lists.php.net to get a copy of this message | ||
On 12 December 2016 09:11:17 GMT+00:00, "Silvio Marijić" <marijic.silvio@gmail.com>
wrote:
>Regarding my proposal above, since copy() would essentially operate
>only on
>immutable objects, why not put it only there. So you would be able to
>make
>a call like this one $immutable->copy(array $args); or
>$this->copy(array
>$args); depending on whether you are inside let's say with* method or
>outside of the object.
If users of the object can set arbitrary (public) properties this way, then you've thrown away
a bunch of the free encapsulation the immutable keyword gave you in the first place. What you get is
an enforced copy-on-write, where you can set the properties to whatever state you like, just not
using normal object passing semantics. That's very different from what the RFC shows, which are
properties which are publicly readable, but whose state is exclusively controlled by the class (and
its descendants).
PS The rule on this mailing list is too always reply *below* the text you're replying to.
--
Rowan Collins
[IMSoP]