Re: [RFC] Object Initializer

From: Date: Fri, 13 Sep 2019 11:26:39 +0000
Subject: Re: [RFC] Object Initializer
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-107075@lists.php.net to get a copy of this message
On Fri, Sep 13, 2019 at 10:51 AM Arnold Daniels < arnold.adaniels.nl@gmail.com> wrote: > Comments: > > I don't like how it works for anonymous classes. It's more difficult to > implement since the compiler doesn't know the meaning of the (first) > bracket. It's doesn't make the code more readable, for the same reason. I > think it's better to not support this syntax with anonymous classes. > > The examples do not show how constructor arguments are passed. I'm assuming > it's > > $customer = new Customer("foo") { > name = "John" > }; > > About the idea of letting { foo = 10 } create an > stdClass object (not > in the RFC); While not used much since it has no effect, it's perfectly > okay to put your code in brackets eg { { { $foo = 10; } } }. As > such, I > don't think it's a good idea to allow new stdClass to > be omitted. > If the compiler implementation of $foo = {...}; would give issues, `$foo = new {...};` could be an alternative for run-time declared anonymous classes (preferably with typed properties). In regards of stdClass, I don't think this should be used. Regards, Lynn van der Berg

« previous php.internals (#107075) next »