You can use func_get_args
. Example:
function foo($optional=null) {
if (count(func_get_args()) > 0)
echo "optional given\n";
else
echo "optional not given\n";
}
foo(); //optional not given
foo(null); //optional given
Note that the convention used for internal PHP functions is to always give optional arguments a default value and to have them have the same behavior when both argument is not given and its default value is explicitly given. If you ever find otherwise, file a bug report. This let's you do stuff like this without if
s:
function strpos_wrap($haystack, $needle, $offset = 0) {
return strpos($haystack, $needle, $offset);
}
This convention is more enforced is userland, as the difficulty that led you to this question has shown you. If the convention doesn't suit your needs, at least reconsider your approach. The purpose of func_num_args
/func_get_args
is mainly to allow variable argument functions.