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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php