Defaulting optional parameters

, Updated by Julian Knight Reading time ~ 1 min.
Posts Development Development, PHP

If you have a function that takes an optional parameter – e.g.

function blah($xx,$yy='Default',$zz){ ....

You can use the function and ensure that the optional parm always takes the correct default (even if the definition changes) by passing a NULL to it. e.g.

...
$mydate=blah($something,NULL,$more);
...

comments powered by Disqus