I have a function that requires as arguments a reference to an array and a reference to a scalar variable. This function passes those arguments to another function, which supplies them to a callback function when it gets executed at a later time, e.g., via call_user_func_args. In some cases, the callback may not require an array of arguments or return a value. Therefore, I want to provide an empty array and a null scalar as default arguments. My question is, is it legal to use a variable's name as a default argument in the function's declaration, as shown in this code?
PHP Code:$empty_array = array();
$null_output = null;
function add_idle($callback,&$args = $empty_array,&$ret = $null_output) {
try {
$handle = rand_str(16);
$idle = IdleTaskList::getInstance();
$idle->addTask($handle,$callback,&$args,&$ret);
return $handle;
}
catch (Exception $e) {
alert($e->getMessage());
return false;
}
} // add_idle





Bookmarks