Is passing NULL param exactly the same as passing no param
No. Presumably, the exact signature is:
function afunc($p1, $p2, $p3, $p4 = SOM_CONST)
and the function uses func_get_arg
or func_get_args
for $p5
.
func_num_args
will be different depending whether you pass NULL. If we do:
{ echo func_num_args();}
then
afunc(1,2,3,4,NULL);
and
afunc(1,2,3,4);
give 5 and 4.
It's up to the function whether to handle these the same.
No. It is only the same if the parameter's default value is NULL
, otherwise not:
function a($a, $b, $c = 42) { var_dump($c);}a(1, 2, NULL);
prints NULL
.
So you cannot say it is always the same. NULL
is just another value and it is not that special.
Not to mention non-optional parameters: Calling a(1)
would give you an error (warning) but a(1,NULL)
works.
Passing NULL
is exactly the same as not passing an argument - if the default value is NULL
, except in the context of the func_num_args
function:
Returns the number of arguments passed to the function.
<?phpfunction test($test=NULL) { echo func_num_args();}test(); //outputs: 0test(NULL); //outputs: 1?>