Re: [RFC] [DISCUSSION] Compact Object Property Assignment
| From: | Marco Pivetta | Date: | Tue, 17 Mar 2020 01:29:25 +0000 |
| Subject: | Re: [RFC] [DISCUSSION] Compact Object Property Assignment | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109087@lists.php.net to get a copy of this message | ||
Hey Jakob,
On Tue, Mar 17, 2020, 02:27 Jakob Givoni <jakob@givoni.dk> wrote:
> On Mon, Mar 16, 2020 at 9:31 AM Marco Pivetta <ocramius@gmail.com> wrote:
> > What happens if you have an expression that throws?
> >
> > class Foo
> > {
> > public $a;
> > public $b;
> > public $c;
> > }
> >
> > $instance = new Foo();
> >
> > function iThrow() {
> > throw new \Exception();
> > }
> >
> > try {
> > $foo ->[
> > a = 'a',
> > b = iThrow(),
> > c = 'c',
> > ];
> > } catch (\Throwable $e) {
> > var_export($foo); // ???
> > }
>
> Hi Marco!
> Trivial question - let's see what happens:
>
> Just replace COPA with the old syntax and run it:
>
> try {
> $foo->a = 'a';
> $foo->b = iThrow();
> $foo->x = 'c';
> } catch (\Throwable $e) {
> var_export($foo); // ???
> }
>
> Result:
> Foo::__set_state(array(
> 'a' => 'a',
> 'b' => NULL,
> 'c' => NULL,
> ))
>
> So the first property will be set, the rest will be left as they were.
>
That kinda makes the entire feature quite useless/uninteresting to me: if a
this does is desugaring into a set of assignments, then I'm not sure what
its advantage is.
I was kinda hoping for an atomic state mutation across multiple fields,
heh...
>