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