Re: Analysis of property visibility, immutability, and cloning proposals
| From: | Chuck Adams | Date: | Wed, 30 Dec 2020 19:36:30 +0000 |
| Subject: | Re: Analysis of property visibility, immutability, and cloning proposals | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112679@lists.php.net to get a copy of this message | ||
On Wed, Dec 30, 2020 at 12:27 PM Larry Garfield <larry@garfieldtech.com> wrote:
>
> If you clone the object, you don't duplicate 15+1 zvals. You duplicate just the one zval
> for the object itself, which reuses the existing 15 internal property entries. If in the new object
> you then update just the third one, PHP then duplicates just that one internal zval and modifies the
> new one. So you still are using only 18 zvals, not 36 zvals. (Engine people: Yes, I am *very*
> over-simplifying. I know.)
>
I've pondered hacking in something like perl's bless() to turn arrays
into value objects, but according to this it looks like an object with
clone-on-write behavior would be better, as I'm assuming arrays do a
full shallow copy: given an array of 15 entries, pass it to a
function, change one member, now you're using 15 more zvals, as
opposed to just one with an object.
Am I reading that right?
--c