Re: [PHP-DEV] [RFC] [DISCUSSION] Compact Object Property Assignment

This is only part of a thread. view whole thread
  109182
March 21, 2020 18:56 cmbecker69@gmx.de ("Christoph M. Becker")
On 21.03.2020 at 19:31, Andrea Faulds wrote:

> However, we don't have to be so imaginitive and adapt a similar feature, > because C# already has the exact feature you are proposing, and calls it > “object initialisers”: > >     Foo foo = new Foo { >         bar = 1, >         baz = 2, >     }; > > (I am again assuming the call to the constructor has no arguments. If > there are arguments, they go before the opening `{` in C#.) > > I am neutral on whether it's a better or worse syntax than using `->`. > > Side-note, C# even supports a special kind of anonymous classes with > “object initialisers”: > >     var foo = new { >         bar = 1, >         baz = 2, >     }; > > I think PHP won't need this given `new stdClass {` would work perfectly > well, although it would be nice to have a shorter and prettier > alternative to the current `(object)[`. > > Anyway, thanks for proposing something I have wanted for ages but never > gotten round to implementing. :)
This is exactly what the recently declined Object Initializer RFC[1] proposed. :) [1] <https://wiki.php.net/rfc/object-initializer> -- Christoph M. Becker