Re: [PHP-DEV] [RFC] Object Initializer

This is only part of a thread. view whole thread
October 7, 2019 07:49 (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=)
Hi Arvids,

sorry for the late response, I've been busy recently.

wt., 17 wrz 2019 o 13:08 Arvids Godjuks>

> > I've have been keeping up with the thread and at this point, I do somewhat > agree with people that maybe the RFC should go into V2 version development. > It really seems like the scope of the RFC is just too small for the feature > and it might be a good idea to expand it a bit. >
I'm gonna let it go as it currently is, there's still time before PHP 8.0 for improvements. IMO with all the goods like list of properties to set and restriction which forces to properly initialize object instance with all required fields is enough.
> Also, I have this question - is there any performance to be gained here? > Cause right now object hydration is an issue and is somewhat slow. Can it > be optimised? > Also, usually I don't really want properties to be public (aka writeable), > so that means `private/protected` and I need to use the methods to set the > properties or reflection. I might have missed or don't remember it, but I > don't think I saw a discussion about that use-case. Value object, DTO's - > all have a big use case for it. >
This feature has no implementation yet so won't speak out about performance and optimisation now. Declaring classes with private/protected fields doesn't mean you cannot to object initialization using object initializer, you can do this from class inner scope exactly the same way as you're able to access them from class inner scope now. This feature may not be a cure for all diseases, but I believe is the right to reduce noise and boilerplate when instantiating and initializing simple objects with type restrictions and ensures valid object state every time it's used. BR, Michał Brzuchalski