Re: Allowing `(object)['key' => 'value']` in initializers?
| From: | Rowan Tommins | Date: | Sat, 25 Sep 2021 16:59:01 +0000 |
| Subject: | Re: Allowing `(object)['key' => 'value']` in initializers? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116162@lists.php.net to get a copy of this message | ||
On 25/09/2021 16:45, tyson andre wrote:
What are your thoughts on allowing theI'm not strongly opposed to this, but am not convinced it's a big improvement. Firstly, as with everything involving stdClass, I would be more interested in a) improving the initialization of anonymous objects, and b) allowing those in initialisers (the RFC currently forbids them, but doesn't say why, so I'm not sure if it's an implementation decision or a philosophical one). Secondly, if you have enough knowledge of the structure to provide an inline default, then you probably have enough to be worth defining a named class, even if that class then implements __set() to allow additional ad hoc properties. That class can then have its own defaults, so that your example becomes(object)cast in initializer types wherenewwas already allowed
function setData(Data $values = new Data())
Regards,
--
Rowan Tommins
[IMSoP]