
Originally Posted by
sessions
Understood. Thanks.
Is it true that with multiple arguments, if one or more arguments have a default value of null that it must be last in the argument list?
i.e.
Code PHP:
function example($value1, $value2 = null){
}
if not is there any situation where this is necessary?
Typically, optional arguments *are* placed last so that when the function is called, you could just call it with the required argument and leave out the optional argument (the one with an existing default value): example("value_a")
There's no rule preventing you from actually changing the order, but if you did, then you would have to call the function with both arguments or the function call wouldn't work properly. Example:
Code:
function example(value2=null, value1){}
Code:
example("value_b","value_a");
Also, see example #5 here: PHP: Function arguments - Manual
Bookmarks