-
-
Notifications
You must be signed in to change notification settings - Fork 327
Private properties of parent classes not injected properly by Container::injectOn()? #257
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
If the property is |
yeah, I understand that. But as you can see the method exists 'in' the Summarizing: the class hierarchy of a class (in this case a controller) Maybe check for existence of parents and also inject them...
|
Ah OK I thought it worked in the parent class since you said this:
So it doesn't work in the parent class too if I understand correctly. In that case this is indeed not normal as it should inject in all properties: we used the same pattern in another ZF1 project and I'm pretty sure we did something similar. I'm going to check a little more and come back to you. |
OK you are right this is a bug! We did use that pattern but we made the properties FYI there is a test for that: https://github.com/mnapoli/PHP-DI/blob/5.0/tests/IntegrationTest/InheritanceTest.php#L23-L53 but it tests for public properties, not private ones. I will fix this in 5.0 thank you for reporting it! |
:), thanks for the swift responses! Indeed, it works when using the default Module (which dispatches the
|
Hi, FYI I will be rescheduling this issue to the next version. I'm sorry about that but v5.0 is ready to be released (I wanted to release this week) and when i started working on this issue I realized it requires a lot of work (at least more time than I have available right now). In the meantime as a workaround you can define your properties as |
Ok, 100% no stress ;). Not sure whether it is related, but I once had to follow a class hierarchy 'stream upwards' as well. In my case to reset all properties to their default values. Especially the private properties were not that trivial. Maybe you can use it as inspiration to inspect upstream defined class/object properties. |
👍 thanks |
@mnapoli, need help / extra eyes with this or have you already pinned down the cause of the mentioned behaviour? |
@holtkamp sorry for the delay! I wrote a test reproducing it: https://github.com/PHP-DI/PHP-DI/compare/257-parent-private-properties But haven't started working on a fix yet :/ |
Great, just upgraded to https://github.com/PHP-DI/PHP-DI/tree/5.1.0 and everything works as expected when using private properties 👍 |
When using Modules in a ZF1 project, it is common to have controllers like this.
Using the
$this->orderDomainService
property works for the default Module, but not for the other Modules. It seems that the current ZF1 integration of the DIC does not inject the values of private properties of parent Controllers / classes. When changing the access level of the property to 'protected', the property does get injected...Is this intended behaviour of
\DI\Container::injectOn()
used by the bridge? It would be nice if the class hierarchy upstream is taken into account as well...PS: offtopic: still looking for a way to get rid of these 'empty' controllers, but seems not possible in ZF1
The text was updated successfully, but these errors were encountered: