Re: RFC - Immutable classes

From: Date: Wed, 07 Sep 2016 18:27:10 +0000
Subject: Re: RFC - Immutable classes
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-95764@lists.php.net to get a copy of this message
On 07.09.2016 at 20:11, Fleshgrinder wrote: > On 9/7/2016 8:57 AM, Michał Brzuchalski wrote: > >> AFAIK CoW in case of objects would be impossible to implement. > > Nothing is impossible. :) > > We have full access to the real object inside of zend_std_write_property > and can easily clone it, perform the desired changes and return without > affecting anyone. > > I am not 100% sure how to do this without fiddling around a bit. > > @nikic and @afaults: I am really sorry to bother you both but you guys > simply know the PHP source endlessly good. What do you think, would it > be possible to implement copy-on-write for an object as we have it with > our scalar and compound types? > > final class A { > public $p; > } > > $a = new A; > $b = $a; > > var_dump($a === $b); // bool(true) > > $b->p = 1; > > var_dump($a === $b); // bool(false) > > It's only about writing to existing properties. Ah, good old PHP 4, see <https://3v4l.org/VaD1W#v5328>. :-) -- Christoph M. Becker

« previous php.internals (#95764) next »