Re: [Proposal] Struct Data Types

From: Date: Sat, 16 Mar 2019 09:12:09 +0000
Subject: Re: [Proposal] Struct Data Types
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-104771@lists.php.net to get a copy of this message
On 15 March 2019 15:26:27 GMT+00:00, Nikita Popov <nikita.ppv@gmail.com> wrote: >On Fri, Mar 15, 2019 at 4:16 PM Levi Morrison <levim@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]

« previous php.internals (#104771) next »