Skip to content

Inject class by annotation in parent class #274

@pgrzesiecki

Description

@pgrzesiecki

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions