1

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);
Ray Carnegie
  • 103
  • 1
  • 7

2 Answers2

1

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

Damian972
  • 11
  • 2
0

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.

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
  • @Mattieu Napoli thanks for the fastest of the answer, but i'd like to know..First is it possible to make parameters null ? two : if yes can i have a snippet as example , to make this work ? – Ray Carnegie Apr 02 '19 at 19:55