Hi Jakob, wt., 17 mar 2020 o 03:08 Jakob Givoni <ja...@givoni.dk> napisał(a):
> On Mon, Mar 16, 2020 at 6:48 AM Jakob Givoni <ja...@givoni.dk> wrote: > > Let me know what you think! > > Thank you for your feedback so far! > > I'd be really curios to know what authors of the referenced RFCs think > about this, f.ex. > Michał (brzuc...@php.net), Andrey (andrewg...@rambler.ru) and Nikita > (ni...@php.net) > > Is simple inline object population useful in itself? > Is the proposed implementation as trivial as I think it is? > For object initializer, I was hoping to introduce a feature which with the benefits of typed properties could reduce the boilerplate on initializing object and setting their properties in one expression. This is somewhat what I personally do a lot for commands and events construction where those simply have public typed properties and I don't care if something would be changed in the meantime. With current RFC for write-once, I can see object initializer could be an awesome feature with a combine of read-only properties. Currently I would have to do a lot of: $command = new SomeCommand(); $command->foo = 'bar'; $command->baz = true $this->dispatch($command); For SomeCommand looking like (with read-only for example purposes) class SomeCommand { public readonly string $foo; public readonly bool $baz; } With object initializer, this could be reduced to: $this->dispatch(new SomeCommand { foo = 'bar', baz = false }); But as mentioned IMO this is a different feature than what you propose and personally I see no point in reducing only assignment statements without combining it with object construction for these kinds of small objects, DTO's, commands, queries and events. And agree with others that brackets look unnatural for anything related to objects. IIRC there were many questions about named parameters to pass for object constructor or proper property setters like in C#, but personally I don't need a constructor at all in those cases since we have typed properties and it looks like they could be also marked as read-only in next major PHP version. Cheers, -- Michał Brzuchalski