Can any one tell which function to use to determine the number of arguments passed within a function that has optional arguments?
1 Answer
You mean func_num_args? That will count the passed arguments, but not those that are not passed and get the default value:
function foo($a, $b='bar') {
echo func_num_args() . PHP_EOL;
}
foo(1);
foo(1,2);
foo(1,'bar');
prints
1
2
2
3 Comments
ThiefMaster
I think he wants to test if a function
xyz($a, $b='') was called like xyz(1) or xyz(1, 'foo')Felix Kling
@ThiefMaster: Isn't that what
func_num_arg is doing? Or I don't get your point...ThiefMaster
Indeed. I thought func_num_args counts all arguments.. no matter if default or passed manually.