I'm trying to use a PHP-DI Call on a method which have a default parameter but i get this error
Fatal error: Uncaught Invoker\\Exception\\NotEnoughParametersException: Unable to invoke the callable because no value was given for parameter 1...
PS : PHP-DI 6
Classe Bill
{
public function index($slug=null,Request $request){
//----
}
}
use DI\ContainerBuilder;
$containerBuilder = new ContainerBuilder;
$container = $containerBuilder->build();
$controller = 'Bill' ;
$method = 'index';
$parameters = [];
$response = $container->call([$controller,$method], $parameters);
Works:
class TestController { function doAction(Request $request, int $id = null) {} }
Does not work:
class TestController { function doAction(int $id = null, Request $request) {} }
Source: https://github.com/PHP-DI/Slim-Bridge/issues/37#issuecomment-368954250
You need to provide a value for the parameter $slug
.
When a parameter is optional before non-optional parameters it cannot be omitted. So you have to provide its value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.