On Thu, Jan 21, 2021, at 4:37 PM, Sara Golemon wrote: > On Thu, Jan 21, 2021 at 3:29 PM Larry Garfield <la...@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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php