-
-
Notifications
You must be signed in to change notification settings - Fork 324
Inject class by annotation in parent class #274
Copy link
Copy link
Closed
Labels
Description
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;
}
}Reactions are currently unavailable