On Wed, Dec 30, 2020 at 12:27 PM Larry Garfield <la...@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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php