Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] always call the parent class' constructor #25762

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

Merged
merged 1 commit into from
Feb 4, 2018

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Jan 11, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25343
License MIT
Doc PR

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a risky change: let's say the parent is customized: what if it has no constructor? or any args (less likely?)

@xabbuh
Copy link
Member Author

xabbuh commented Jan 11, 2018

Could happen, but right now we already call the parent constructor if the container is not compiled. Not doing this for compiled containers leads to inconsistencies and to issues as described in the linked issue.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 11, 2018

On the other hand, uncompiled containers are not a thing, so their code path is mostly dead (we even removed it in 4.0.)

@xabbuh
Copy link
Member Author

xabbuh commented Jan 11, 2018

Hm indeed, you are right about that. Should we do some reflection then and try to find out if there is a constructor that could be called instead?

@nicolas-grekas
Copy link
Member

Looks great yes. We should ensure that there is a constructor, and that it has zero mandatory args.

@nicolas-grekas
Copy link
Member

On 3.4 only? I'd prefer not change any behavior on 2.*

@xabbuh xabbuh modified the milestones: 2.7, 3.4 Jan 15, 2018
@xabbuh xabbuh changed the base branch from 2.7 to 3.4 January 18, 2018 08:32
@xabbuh xabbuh force-pushed the issue-25343 branch 6 times, most recently from ae89452 to e18186b Compare January 18, 2018 11:41
@@ -970,9 +976,20 @@ public function __construct()
}

if ($this->container->isCompiled()) {
try {
$r = new \ReflectionClass($baseClassWithNamespace);
Copy link
Member

@nicolas-grekas nicolas-grekas Jan 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$container->getReflectionClass()? (then no need to try/catch)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

try {
$r = new \ReflectionClass($baseClassWithNamespace);

if ((null !== $constructor = $r->getConstructor()) && 0 === $constructor->getNumberOfRequiredParameters()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& $baseClassWithNamespace !== Container::class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (($constructor = $r->getConstructor()) && !$constructor->getNumberOfRequiredParameters() && $baseClassWithNamespace !== Container::class) {?

@xabbuh xabbuh force-pushed the issue-25343 branch 3 times, most recently from 34d463a to ac4b2f6 Compare January 22, 2018 13:35
@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit a1b1484 into symfony:3.4 Feb 4, 2018
nicolas-grekas added a commit that referenced this pull request Feb 4, 2018
…uctor (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[DependencyInjection] always call the parent class' constructor

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25343
| License       | MIT
| Doc PR        |

Commits
-------

a1b1484 always call the parent class' constructor
@xabbuh xabbuh deleted the issue-25343 branch February 4, 2018 12:34
This was referenced Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.