5
I’m having a problem with the parameters in a PHP function.
For example:
function exemplo($par1 = 1, $par2 = 2) {
return $par1 . " - " . $par2;
}
exemplo(); // 1 - 2
exemplo(3); // 3 - 2
exemplo(3, 4); // 3 - 4
exemplo(null, 4); // - 4
On the last call, I’m trying to pass just the according to parameter and keep the first as default, but that’s not what happens (the variable gets value null
).
It is possible to achieve the desired behavior in this case?
For less gambit, http://php.net/manual/en/functions.arguments.php#functions.variable-Arg-list
– Édipo Costa Rebouças
@I don’t think it’s funny, because the php page that I mentioned, future intends to adopt a syntax similar to this, see the section Open questions, and see also the section
func_* and call_user_func_array
.– stderr
I understood your point, I think you could quote the named params more clearly in your answer, rather than using "this feature".
– Édipo Costa Rebouças