You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into a situation where the container gives me an error message pointing me in the wrong direction. In the scenario, there are two dependencies that have strings as arguments to the constructor. One of the dependencies are declared with a contextual binding ( a when-call) but the other one is not.
The container gives me the following error message in the example below: Unresolvable dependency resolving [Parameter #0 [ <required> string $a ]] in class App\Console\Commands\Secondary. This dependency is not unresolvable as it has been declared.
I would expect the error message to instead be: Unresolvable dependency resolving [Parameter #0 [ <required> string $c ]] in class App\Console\Commands\DeepTwo. Adding
Declaring DeepTwo as a singleton solves the problem, making Main resolvable via the container.
The problem only seems to occur when the contructor argument in DeepOne has a default value. If I remove the = null i get the correct error message from the container.
Please let me know if this is not reproducible or if I can help in any other way.
Steps To Reproduce:
Run this as a command:
<?phpnamespaceApp\Console\Commands;
useIlluminate\Console\Command;
useIlluminate\Container\Container;
class Main
{
publicfunction__construct(DeepOne$deepOne, Secondary$secondary)
{ }
}
class DeepOne
{
// Removing the `= null` in here will result in the correct error-message// being shown.publicfunction__construct(DeepTwo$c = null)
{ }
}
class DeepTwo
{
publicfunction__construct(string$a)
{ }
}
class Secondary
{
publicfunction__construct(string$a, string$b)
{ }
}
class ContainerBug extends Command
{
protected$signature = 'bug:demo';
protected$description = 'Container bug demonstration';
publicfunctionhandle()
{
$container = Container::getInstance();
$container->when(Main::class)
->needs(Secondary::class)
->give(function () {
returnnewSecondary('a', 'b');
});
// Uncommenting this resolves the unresolved dependency// $container->singleton(DeepTwo::class, function () {// return new DeepTwo('a');// });$res = $container->make(Main::class);
$this->info('done, without errors');
}
}
The text was updated successfully, but these errors were encountered:
Description:
I ran into a situation where the container gives me an error message pointing me in the wrong direction. In the scenario, there are two dependencies that have strings as arguments to the constructor. One of the dependencies are declared with a contextual binding ( a
when
-call) but the other one is not.The container gives me the following error message in the example below:
Unresolvable dependency resolving [Parameter #0 [ <required> string $a ]] in class App\Console\Commands\Secondary
. This dependency is not unresolvable as it has been declared.I would expect the error message to instead be:
Unresolvable dependency resolving [Parameter #0 [ <required> string $c ]] in class App\Console\Commands\DeepTwo
. AddingDeclaring
DeepTwo
as a singleton solves the problem, makingMain
resolvable via the container.The problem only seems to occur when the contructor argument in
DeepOne
has a default value. If I remove the= null
i get the correct error message from the container.Please let me know if this is not reproducible or if I can help in any other way.
Steps To Reproduce:
Run this as a command:
The text was updated successfully, but these errors were encountered: