Re: [RFC] Null Coalescing Assignment in Method Signature

From: Date: Thu, 21 Jan 2021 23:40:05 +0000
Subject: Re: [RFC] Null Coalescing Assignment in Method Signature
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-112962@lists.php.net to get a copy of this message
On Thu, Jan 21, 2021, at 4:37 PM, Sara Golemon wrote: > On Thu, Jan 21, 2021 at 3:29 PM Larry Garfield <larry@garfieldtech.com> > wrote: > > > > I'm unclear why you'd allow null at all then. > > If you want $bar to be optional, and to be an empty array if not > specified, then just do: > > > > function foo(array $bar = []) { ... } > > > > At that point, the only thing adding ?array does is allow you to > explicitly pass null, > > presumably because it has some meaning to your function. > > If you don't want that, don't allow it. > > > > Smells a little like it's verging on the default proposal > that was > brought up awhile ago... > > function foo(int $a, array $b = [], string $c = '') { ... } > foo(123, default, "bar"); > > In this case, foo() never wants null as a valid value, but > neither does > the caller actually want anything different from the default. > > Allowing a null-coalescish sort of initializer is another potential way to > solve this problem, and I'm not here to say I endorse any of them, but > maybe that's the intent. > > -Sara I'd argue that named arguments have rendered the main argument for default null and void. (How many puns can he squeeze into one sentence, Bob?) --Larry Garfield

« previous php.internals (#112962) next »