I wanted to know if the new feature of nullable types can be used to change the syntax in this working function from
function getCustomerId($id = null)
{
return $id ?: 2;
}
echo getCustomerId();
to something like this which isn't working for me. I get the error for too few arguments.
function getCustomerId(?int $id)
{
return $id ?: 2;
}
echo getCustomerId();
so that basically if the argument is not provided it returns 2, but if the argument is provided it returns that argument.