I noticed a problem with dependency injection by annotation, when injection is in parent class.
To illustrate:
class MyClass {
/**
* @Inject
* @var Children
*/
protected $serviceMyClass;
public function test() {
$this->serviceMyClass->checkMethods();
}
}
and children with parent:
class Parent {
/**
* @Inject
* @var ServiceParent
*/
protected $serviceParent;
}
class Children extends Parent {
/**
* @Inject
* @var ServiceChildren
*/
protected $serviceChildren;
public function checkMethods() {
var_dump($this->serviceChildren); // /ServiceChildren
var_dump($this->serviceParent); // NULL (should be object /ServiceParent)
}
}
Let's assume that both ServiceParent and ServiceChildren exist and are achievable.
serviceParent is not injected.
This issue does not occur in 4.* version.
For injection by constructor, it looks ok:
class Parent {
/**
* @var ServiceParent
*/
protected $serviceParent;
public function __construct(ServiceParent $serviceParent) {
$this->serviceParent = $serviceParent;
}
}
I noticed a problem with dependency injection by annotation, when injection is in parent class.
To illustrate:
and children with parent:
Let's assume that both
ServiceParentandServiceChildrenexist and are achievable.serviceParentis not injected.This issue does not occur in 4.* version.
For injection by constructor, it looks ok: