DI\Container::make fails silently and returns null when provided argument is not provided by reference, but the dependency expects it to be passed by reference. In example
class A
{
}
class B
{
public function __construct(A &$aInstance, SomeOtherDependencies $baz)
{
}
}
$foo = $container->get('A');
// do some stuff to $foo
try
{
$bar = $container->make('B', [
'aInstance' => $foo
]);
}
catch(DependencyException $e)
{
// never gets fired
}
echo is_object($bar) ? get_class($bar) : gettype($bar); // prints 'NULL'
$barReal = $container->make('B', [
'aInstance' => &$foo
]);
echo is_object($bar) ? get_class($bar) : gettype($bar); // prints 'B'
Whereas, DI\FactoryInterface defines that a DI\DependencyException will be thrown when there is an error while resolving the entry; however, the exception is not thrown
Whereas, \ReflectionParameter::isPassedByReference() is available to check if the parameter should be passed by reference
Therefore,
DI\Container::make should throw a DI\DependencyException if DI\Definition\Resolver\ObjectCreator::createInstance is unable to provide an object of a class after calling \ReflectionClass::newInstanceArgs(array $args)
- I believe the
DI\Definition\Resolver\ParameterResolver::resolveParameters() should check if \ReflectionParameter::isPassedByReference() is true
DI\Container::makefails silently and returnsnullwhen provided argument is not provided by reference, but the dependency expects it to be passed by reference. In exampleWhereas,
DI\FactoryInterfacedefines that aDI\DependencyExceptionwill be thrown when there is anerror while resolving the entry; however, the exception is not thrownWhereas,
\ReflectionParameter::isPassedByReference()is available to check if the parameter should be passed by referenceTherefore,
DI\Container::makeshould throw aDI\DependencyExceptionifDI\Definition\Resolver\ObjectCreator::createInstanceis unable to provide an object of a class after calling\ReflectionClass::newInstanceArgs(array $args)DI\Definition\Resolver\ParameterResolver::resolveParameters()should check if\ReflectionParameter::isPassedByReference()is true