Re: [RFC] [DISCUSSION] Compact Object Property Assignment

From: Date: Wed, 18 Mar 2020 02:57:17 +0000
Subject: Re: [RFC] [DISCUSSION] Compact Object Property Assignment
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-109120@lists.php.net to get a copy of this message
On Tue, Mar 17, 2020 at 9:31 AM Rowan Tommins <rowan.collins@gmail.com> wrote: > Hm, I see, that does reduce the boilerplate somewhat, although it's still > split across two classes, and probably therefore two files, which is not > great. As an alternative to passive associative arrays, it's a small price to pay for splitting concerns and having a documented signature for the data structure. Named parameters is another alternative (unfortunately outside reach for now) that would work great for a limited number of arguments. COPA does not make named parameters obsolete, but works great for any number of arguments. > You're missing some code in your example, though, because you've documented > one of the options as optional, implying the others should be mandatory; in > which case you need something like this in the constructor: I've rewritten parts of the RFC and some examples substantially, and added your view of mandatory arguments in the "Open Issues" section. > It might be interesting to have the syntax run before the constructor > rather than after, or trigger some other magic method which could do > tidying and validation, so it could apply to more circumstances. Hmmm, in the Write Once Properties RFC they seem to believe that object construction is a "fuzzy" term and that lazy initialization is a feature. We can add better 'automagic' support for mandatory arguments, filtering and validation in incremental proposals, to avoid biting off more than we can chew, but we have to start somewhere.

« previous php.internals (#109120) next »