function callme() {
//stuff
return function($type = '%') use (&$data) {
//stuff goes here
return $data;
};
}
如何传递参数以覆盖$type
我只需要一些例子。
答案 0 :(得分:1)
首先调用callme()
来获取该功能。然后调用该函数并传递一个参数:
$fn = callme();
$fn("whatever you want to pass");
答案 1 :(得分:1)
当我读到这个问题时,我理解它,因为你想传递返回函数中的默认值。我虽然:
function callme($default_type = '%') {
//stuff
return function($type = $default_type) use (&$data) {
print "$type\n";
//stuff goes here
return $data;
};
}
但这是语法错误。然后最好的方法是做这样的事情:
function callme($default_type = '%') {
//stuff
return function($type = null) use (&$data, $default_type) {
if( $type === null )
$type = $default_type;
print "$type\n";
//stuff goes here
return $data;
};
}
$fn = callme("maybe");
$fn(); // prints "maybe"
$fn("Carly Rae Jepsen"); // prints "Carly Rae Jepsen"
答案 2 :(得分:0)
call_user_func(callme(), 'type argument here');