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

Inject class by annotation in parent class #274

Closed
pgrzesiecki opened this Issue Jun 22, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@pgrzesiecki

pgrzesiecki commented Jun 22, 2015

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

This comment has been minimized.

Show comment
Hide comment
@mnapoli

mnapoli Jun 22, 2015

Member

Hi, thanks for the report. Are you sure it works with 4.*? Is the parent property private, protected or public?

There is #257 that is very similar, but it's only for private properties, and it is both in 4.* and 5.0.

Member

mnapoli commented Jun 22, 2015

Hi, thanks for the report. Are you sure it works with 4.*? Is the parent property private, protected or public?

There is #257 that is very similar, but it's only for private properties, and it is both in 4.* and 5.0.

@pgrzesiecki

This comment has been minimized.

Show comment
Hide comment
@pgrzesiecki

pgrzesiecki Jun 22, 2015

:) Thanks for quick response.

I'm sure, I have a running project based on PHP-DI 4.4.7 and the same code is injected without any problems. This issue occurred after update to 5.0.0

pgrzesiecki commented Jun 22, 2015

:) Thanks for quick response.

I'm sure, I have a running project based on PHP-DI 4.4.7 and the same code is injected without any problems. This issue occurred after update to 5.0.0

@mnapoli

This comment has been minimized.

Show comment
Hide comment
@mnapoli

mnapoli Jun 22, 2015

Member

Ok, then is it a private, protected or public property?

Member

mnapoli commented Jun 22, 2015

Ok, then is it a private, protected or public property?

@pgrzesiecki

This comment has been minimized.

Show comment
Hide comment
@pgrzesiecki

pgrzesiecki Jun 22, 2015

My mistake I forgot to add. All of them are protected.

pgrzesiecki commented Jun 22, 2015

My mistake I forgot to add. All of them are protected.

@mnapoli

This comment has been minimized.

Show comment
Hide comment
@mnapoli

mnapoli Jun 22, 2015

Member

OK thanks I'll schedule it for next release. What is weird is that there is a test for this, but maybe it only tests for public methods.

Member

mnapoli commented Jun 22, 2015

OK thanks I'll schedule it for next release. What is weird is that there is a test for this, but maybe it only tests for public methods.

@mnapoli mnapoli added the bug label Jun 22, 2015

@mnapoli mnapoli added this to the 5.1 milestone Jun 22, 2015

@mnapoli

This comment has been minimized.

Show comment
Hide comment
@mnapoli

mnapoli Sep 1, 2015

Member

It's actually a duplicate of #257, closing.

Member

mnapoli commented Sep 1, 2015

It's actually a duplicate of #257, closing.

@mnapoli mnapoli closed this Sep 1, 2015

@mnapoli mnapoli removed this from the 5.1 milestone Sep 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment