This problem seemed obvious at first to me but I've been struggling for a while and I can't find any useful information on internet/stack overflow regarding this.
I have a function that looks like this :
myfunction(string $parameter, array $optionalParameter = []) {
}
and in my call, something like that :
myfunction('text', BOOL ?? $array);
The problem is that, from what I understand, passing null
as the second argument isn't the same as having no second argument, so $optionalParameter
isn't initialized (I use phpstan and it tells me that null is incompatible with array).
The only solution I can envision would be to duplicate the function call, but it's really not a good idea considering my actual function has way more than 2 parameters.
TLDR; I'm looking for a way to turn the return type of BOOL ?? $array
from array|null
to array|(nothing)
if that makes sense