Re: [RFC] [Discussion] Clone with

From: Date: Tue, 18 Apr 2023 09:27:20 +0000
Subject: Re: [RFC] [Discussion] Clone with
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-120065@lists.php.net to get a copy of this message
Hello Máté, internals, I have been waiting for this to happen :) Some feedback > However, in some cases it would be useful to reference property names as expressions, e.g. when > one needs to use “clone with” in a foreach loop where the index is the property name and the > loop variable is the value to be assigned. This is also possible using a slightly more verbose > syntax: What about argument unpacking? I don't know if we can combine this with ":" syntax or only with "=>". clone $object with { ...$arr, ...['a' => 'A', $b => 'B'], ...(function () {yield 'x' => 'X';})(), c: 'C', // or d => 'D', // No mixing of ':' and '=>', we have to choose one. } If we want to go crazy in the future: (This would require another language feature of inline code blocks with return value or behaving as generator) clone $object with { ...{ yield 'a' => 'A'; yield 'b' => 'B'; }, ...{ return ['c' => 'C'], } } -- Andreas On Mon, 17 Apr 2023 at 08:32, Máté Kocsis <kocsismate90@gmail.com> wrote: > > Hi Everyone, > > Quite some time after mentioning the "clone with" construct the first time > (at the end of the > > https://wiki.php.net/rfc/write_once_properties#run-time_behaviour > section), > finally I managed to create a working implementation for this feature which > would make it possible to properly modify readonly properties > while simplifying how we write "wither" methods: > https://wiki.php.net/rfc/clone_with > > Regards, > Máté Kocsis

« previous php.internals (#120065) next »