In PHP 7.1 when the following function is called:
private function doStuff(?int $limit = 999) { }
with syntax like so:
doStuff(null);
the value of $limit becomes null. So I guess it can be said that the value of $limit was explicitly set to null.
Is there any way to overcome this? I.e. when a null value (i.e. the lack of a value) is encountered use the default, whether it is implicit or explicit?
dostuff()without parameters, and this will take the default value, if you sentnullvalue to the function, I don't think that it will take the default value all by itself, but you can still catch this inside the function and set the default value by code.if(is_null($limit)) $limit = 999;as the first line of the function codedostuff();it will use the default value you have set in the function's parameternullas its value instead of the declared type or its default value. And that's exactly what happens.NULLin SQL kinda plays outside the type system. In PHP, and many other languages for that matter, it's simply yet another type/value.