generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Labels
Description
What steps will reproduce the problem?
Having the sample code:
class A
{
public function __construct()
{
throw new RuntimeException('Something happened on initialization');
}
}
class B
{
public function __construct(private ?A $a = null)
{
}
}
$container->get(B::class);What is the expected result?
The exception is thrown
What do you get instead?
Instance of B with a wrong dependency, and no exception is thrown. It' a hell to debug this situation.
Additional info
This code is responsible for the specified behavior. I'm pretty sure container definitions must not have a deal with application-level exceptions. In my opinion in the case when a dependency has a definition, and an exception is thrown on its resolving, this exception must not be catched by container/definition resolver, and doesn't matter if this dependency is optional or not.