On 15 March 2019 15:26:27 GMT+00:00, Nikita Popov <nikita....@gmail.com> wrote:
>On Fri, Mar 15, 2019 at 4:16 PM Levi Morrison <le...@php.net> wrote:
>
>> Personally, I think pass by-value with copy-on-write semantics like
>> arrays is the sweet spot. Mutability is fine if it is localized.
>>
>
>If we introduce something like this, I think it is very important that
>it
>does not use the same property access syntax as ordinary objects, which
>are
>not copy-on-write. I do not want to be second guessing whether $x->y = $z
>is going to copy or not.

The more I think about this, the less I agree with it.

Firstly, copy-on-write is an implementation detail; the actual semantic we're 
talking about is by-value passing and assignment. So semantically, $x->y = $z 
would just be modifying local variable $x, as normal. It's actually doFoo($x) 
and $x2 = $x which cause the copying, and those look the same for objects and 
arrays.

Secondly, array syntax would prevent us from having any methods available on 
structs. I suppose you could mix $foo['bar'] for property access and 
$foo->doThing() for method calls, but if doThing() was allowed to modify the 
object, you've lost the visual highlight of "may cause COW".

A pass-by-value struct would basically just be a way to reduce the overhead to 
both the programmer and the engine of sprinkling a codebase with the word 
"clone".

Regards,

-- 
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to