You can also check if you have an empty string as argument so you can call like:
foo('blah', "", 'non-default y value', null);
Below the function:
function foo($blah, $x = null, $y = null, $z = null) {
if (null === $x || "" === $x) {
$x = "some value";
}
if (null === $y || "" === $y) {
$y = "some other value";
}
if (null === $z || "" === $z) {
$z = "some other value";
}
code here!
}
It doesn't matter if you fill null
or ""
, you will still get the same result.