-
-
Notifications
You must be signed in to change notification settings - Fork 328
Errors when parameters are passed by reference #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, thanks for the report.
Yep definitely agree. I have to admit I have never used the container with parameters passed by reference, I'm surprised it doesn't even throw an exception but I've never tested it :/ Ideally though it should work and not throw an exception or return null.
The parameter doesn't need to be passed by reference when creating the instance. It's already marked with class A {
public $foo;
}
class B {
public function __construct(A &$a) {
$a->foo = 'hello';
}
}
$a = new A();
$b = new B($a);
echo $a->foo; // hello |
Following up on checking
Is my understanding of those assignment statements in PHP correct? I apologize that I didn't clarify that in my initial suggestion. |
OK I see what you meant! Indeed the reference might be lost at points like that, I was thinking of the actual method/constructor call. |
…_by_reference Fixed #306 modifying ParameterResolver and ObjectCreator
DI\Container::make
fails silently and returnsnull
when provided argument is not provided by reference, but the dependency expects it to be passed by reference. In exampleWhereas,
DI\FactoryInterface
defines that aDI\DependencyException
will 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::make
should throw aDI\DependencyException
ifDI\Definition\Resolver\ObjectCreator::createInstance
is 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 trueThe text was updated successfully, but these errors were encountered: