-
-
Notifications
You must be signed in to change notification settings - Fork 324
Errors when parameters are passed by reference #306
Copy link
Copy link
Closed
Description
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::makeshould throw aDI\DependencyExceptionifDI\Definition\Resolver\ObjectCreator::createInstanceis 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
Reactions are currently unavailable