Re: [RFC] Named arguments

From: Date: Tue, 05 May 2020 15:38:19 +0000
Subject: Re: [RFC] Named arguments
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-110007@lists.php.net to get a copy of this message
Hey Larry, On Tue, May 5, 2020 at 5:29 PM Larry Garfield <larry@garfieldtech.com> wrote: > The biggest use case I see is, as discussed previously, value object > constructors. "Pass an entirely untyped and undocumentable array of > parameters" is not an sufficient userland solution in my mind, but is the > only available alternative right now. > This is easily mitigated by named constructors ( https://verraes.net/2014/06/named-constructors-in-php/), which are a good/established practice among those using value objects. You can create multiple (meaningful) constructor signatures depending on use-case, which is still a much safer approach than delegating this responsibility to a caller. My example above uses a ::fromArray() "factory" precisely for that purpose. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/

« previous php.internals (#110007) next »