This topic created in 4352 days ago, the information mentioned may be changed or developed.
比如
$f=function($test){
echo $test;
};
$p="ldjfosjfsofj";
有个函数 function call($func,$para){
一般可以这样调用 $func($para);
但这里能不能根据函数体和参数 组装出一个Closure呢?
}
1 replies • 2014-06-16 10:09:34 +08:00
 |
|
1
foccy Jun 16, 2014
function make() { $params = func_get_args(); $func = array_shift($params); return function() use ($func, $params) { return call_user_func_array($func, $params); }; }
$foo = 'Foo';
$bar = 'Bar';
$sayHi = function($to, $from) { echo 'Hi, ' . $to . '. I\'m ' . $from . '.'; };
$closure = make($sayHi, $foo, $bar);
$closure(); // output: 'Hi, Foo, I'm Bar.' 不知道是不是这个意思
|