Re: [Proposal] Struct Data Types

From: Date: Fri, 15 Mar 2019 15:38:01 +0000
Subject: Re: [Proposal] Struct Data Types
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-104751@lists.php.net to get a copy of this message
On Fri, 15 Mar 2019 at 15:26, Nikita Popov <nikita.ppv@gmail.com> 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]

« previous php.internals (#104751) next »