Re: RFC - Immutable classes
| From: | Silvio Marijić | Date: | Wed, 07 Sep 2016 18:44:27 +0000 |
| Subject: | Re: RFC - Immutable classes | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-95765@lists.php.net to get a copy of this message | ||
@Fleshgrinder
I will make changes that if immutable objects are being compared that they
will be compared by value rather then hash
On Sep 7, 2016 8:27 PM, "Christoph M. Becker" <cmbecker69@gmx.de> wrote:
> 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
>
>