Re: RFC - Immutable classes

From: Date: Thu, 08 Sep 2016 13:27:16 +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-95794@lists.php.net to get a copy of this message
On 08.09.2016 at 09:41, Silvio Marijić wrote: > I get the nostalgia :) > I think that *zend_compare_symbol_tables* compares only hash tables whether > they contain same properties regardless of the values. What I wanted to show was that PHP 4 objects implemented copy-on-write semantics; the test script doesn't show that, because === triggers a value comparision in PHP 4 (didn't know that). However, <https://3v4l.org/b6UcS> shows that we had copy-on-write for PHP 4 objects. Cheers! > 2016-09-07 20:44 GMT+02:00 Silvio Marijić <marijic.silvio@gmail.com>: > >> @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>. :-)

« previous php.internals (#95794) next »