//声明需要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逻辑
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]();
}
}
在controller
方法中,我会生成Benz
、Audi
的实例传给匿名函数并调用,但是怎样将数量可变的参数给匿名函数呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
http://www.php.net/manual/en/...