Re: [RFC] [Discussion] Clone with

From: Date: Wed, 19 Apr 2023 15:26:58 +0000
Subject: Re: [RFC] [Discussion] Clone with
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-120072@lists.php.net to get a copy of this message
On Tue, 18 Apr 2023 at 22:01, Bob Magic <bob@majdak.net> wrote: > > > [1] In fact if the right hand side of with may be an expression that > > evaluates to an array, folks wouldn't need to learn new syntax at all: > > > > $newProperties = [ "foo" => "bar" ]; > > clone $object with $newProperties; > > > > and > > > > clone $object with [ "foo" => "bar" ]; > > in my opinion this is sick, as in awesome. the {} version makes no sense to > me unless the language gains $var = {} ; to skip $var = (object)[]; I think the {...} is meant to be simply an "argument list", not a value. But yes having an array here would add some flexibility. It would also give us argument unpacking for free. I wonder what this means for performance. Will the expression always be evaluated as an array first, and then applied, or can php do a "shortcut" where it internally treats it as an argument list, even though the syntax implies array? The different will be small, but it could become relevant if called many times over. -- Andreas

« previous php.internals (#120072) next »