On Mon, Mar 16, 2020 at 10:40 AM Rowan Tommins <rowan.coll...@gmail.com> wrote: > Thanks for having another go at this feature, which I think a lot of people > would like in some form. I agree!
> Maybe we want to have all four, but that would leave us with a lot of > different ways of initialising objects, which might not be such a good > thing. Remember that the RFC explicitly says it's not an object initializer, nor does it solve "named parameters" which you mention. If I had the choice, I'd go with named parameters when creating an object, but I don't and this is the next best thing. It's simple and it doesn't introduce any new concepts. It just allows you to do something inline that you could until now only do line by line. > You mention using "argument bag" objects in place of named parameters, but > that feels like it would be even more awkward than using an associative > array. The associative array is a common pattern, but it defeats name and type checking. An Options class add almost no extra boilerplate since you simply move the properties from the main class to the Options class. Notice that in contrary to your example, I simply copy the Options object whole into the main class. > COPA can only validate individual > parameters, not the whole object; so it's hard to complain if the user > forgets a mandatory field Correct, the goals for COPA are quite clear in the "Motivation" section and that kind of validation is not one of them Luckily you can still do things the way you prefer without COPA if it doesn't suit you :-) Best, Jakob -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php