-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
[BUG] New __construct() does not call parent::__construct() #4457
Comments
I also had a similar problem when extending
The reason is that while
The solution was to add the required constructor properties into the newly created The correct constructor signature is:
(first two are the required parameters from the grandparent class, the last one is the injected service) |
The constructor injection with
did work in TYPO3v10, but does not anymore with TYPO3v11. The dependency injection documentation says:
Maybe this is the reason. (v13 still has the same note). So typo3-rector rule should generate different code depending on the constructor parameters - when the class has required parameters, it should keep the injectX methods. |
Sometimes you have to exclude certain directories from Rector and this is such a thing, as covering all different kind of edge cases would be way too complicated. ->withSkip([
InjectMethodToConstructorInjectionRector::class => [
__DIR__ . '/../../Classes/ViewHelpers/',
],
]) |
But then I have to know about the problem, which I don't. |
This rule does exactly what is says, transform inject methods into a constructor without checking for a parent constructor. If you can't apply this rule, you have to exclude it yourself. That is why you should always dry-run rector before applying the code changes. Writing rector rules is already quite challenging and thinking about every possible edge case is almost impossible. We as a team have also already thrown away some rules that became so complicated to implement that it wasn't worth it to maintain them. |
I found out that dependency injection in TYPO3 does not work for classes that have non-service parameters in their So the "only" thing the |
Minimal PHP Code Causing Issue
When applying the
InjectMethodToConstructorInjectionRector
rule, a new__construct()
method is created.Unfortunately, the
parent::__construct()
method is not called, preventing initialization of internal properties.This leads to an error:
Applied rules
InjectMethodToConstructorInjectionRector
Expected Behaviour
If the parent class has a
__construct()
method, it should be called in the newly generated constructor.Package Version
2.12.0
PHP Version
8.2.24
TYPO3 Version
10.4.37
Notes
No response
The text was updated successfully, but these errors were encountered: