On Fri, 15 Mar 2019 at 15:26, Nikita Popov <[email protected]> wrote:
> 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. Possibly such struct types should indeed use the
> array access syntax, because array access is generally copy-on-write (the
> exception being ArrayAccess objects).
>
The problem I see with using array-access syntax is that it implicitly
encourages dynamic property access, because the argument is syntactically a
string, not an identifier.
$foo['bar'] = 42;
$foo['bar' . '_2'] = 69; // looks just the same
vs
$foo->bar = 42;
$foo->{ 'bar' . '_2' } = 69; // clearly doing something unusual
I see your point about making the COW more obvious, but I think it should
also be obvious that you're working with a structured type, not a
collection.
We need to invent some more punctuation to use! ;)
Regards,
--
Rowan Collins
[IMSoP]