Re: [RFC] [DISCUSSION] Compact Object Property Assignment
| From: | Christoph M. Becker | Date: | Sat, 21 Mar 2020 18:56:02 +0000 |
| Subject: | Re: [RFC] [DISCUSSION] Compact Object Property Assignment | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109182@lists.php.net to get a copy of this message | ||
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