Thank you, Michał, for chiming in :-)

On Tue, Mar 17, 2020 at 10:52 AM Michał Brzuchalski
<michal.brzuchal...@gmail.com> wrote:
> 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.
Exactly my motivation with COPA as well;
- Typed properties - check,
- Reduce boilerplate - check,
- Initializing and setting properties in one expression - check.

> With object initializer, this could be reduced to:
>
> $this->dispatch(new SomeCommand { foo = 'bar', baz = false });
And with COPA it would be;
$this->dispatch((new SomeCommand)->[ foo = 'bar', baz = false ]);
Subtle differences, when compared to the currently available alternative.

> 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.
Maybe you missed that COPA can be combined with object construction?

> 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.
Exactly, and as I couldn't help notice that you voted for the Write
Once Properties RFC, which clearly states that
object construction is a fuzzy term (meaning don't take it too
seriously) and lazy initialization is a feature...

I hope you will either reconsider your support for COPA or let me know
what I'm missing so I can
consider other directions.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to