Re: [RFC] Object Initializer

From: Date: Fri, 13 Sep 2019 08:51:39 +0000
Subject: Re: [RFC] Object Initializer
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-107059@lists.php.net to get a copy of this message
This can easily be done in a number of ways, like the suggested helper function. The same can be said for many other features that were implemented recently, like array unpacking. This feature is easy to implement and will make the code for data objects much more readable, with additional benefits for static analysis. 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.

« previous php.internals (#107059) next »