function callme() {
//stuff
return function($type = '%') use (&$data) {
//stuff goes here
return $data;
};
}
上書きするパラメータを渡すにはどうすればよいですか$type
いくつかの例が必要です。
function callme() {
//stuff
return function($type = '%') use (&$data) {
//stuff goes here
return $data;
};
}
上書きするパラメータを渡すにはどうすればよいですか$type
いくつかの例が必要です。
その質問を読んだとき、返された関数でデフォルトであるべきものを渡したいと思ったので、それを理解しました。私は考えました:
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"