作者:mobiledu2502918487 | 来源:互联网 | 2023-10-13 13:04
1234567//声明需要Benz和Audi,将其实例化后传入方法$app->controller("Benz", "Audi", function ($Benz, $Audi){ echo $
1 2 3 4 5 6 7
| //声明需要Benz和Audi,将其实例化后传入方法
$app->controller("Benz", "Audi", function ($Benz, $Audi){
echo $Audi->go()->speedUp()->speedUp()->speedUp()->speedDown()->getSpeed();
echo $Benz->go()->speedUp()->speedUp()->speedUp()->speedDown()->getSpeed();
echo "\n";
echo "arrival";
}); |
controller逻辑
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class App{
function controller(){
$args = func_get_args();
$reliable = [];
foreach ($args as $arg){
if(!is_callable($arg)){
$rf = new \ReflectionClass( "\" . __NAMESPACE__ . "\" . $arg);
$instance = $rf->newInstance();
$reliable[$arg] = $instance;
}
}
//这里如何传入参数
$args[count($args) - 1]();
}
} |
在
方法中,我会生成
、
的实例传给匿名函数并调用,但是怎样将数量可变的参数给匿名函数呢?