PHP:如何使用变量作为依赖项注入的闭包类型

PHP:如何使用变量作为依赖项注入的闭包类型,php,laravel,Php,Laravel,我正在尝试处理许多错误,如下所示: App::error(function(App\Exceptions\RuntimeException $exception, $code) use ($someOther) { ... } 我可以使用变量作为独立注入的类型吗 $errorTypes = [ ... ]; foreach ($errorTypes as $errType) { App::error(function($errType $exception, $code) use

我正在尝试处理许多错误,如下所示:

App::error(function(App\Exceptions\RuntimeException $exception, $code) use ($someOther) { ... }
我可以使用变量作为独立注入的类型吗

$errorTypes = [ ... ];

foreach ($errorTypes as $errType) {

    App::error(function($errType $exception, $code) use ($someOther) {

您可以提示可调用的元类型。另外,传递一个声明的closure对象是可能的。type将用于依赖项注入,所以我不能使用callable。