8000 [DI] Compiled Container Does Not Call Base Class Constructor · Issue #25343 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Compiled Container Does Not Call Base Class Constructor #25343

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

Closed
kiler129 opened this issue Dec 5, 2017 · 4 comments
Closed

[DI] Compiled Container Does Not Call Base Class Constructor #25343

kiler129 opened this issue Dec 5, 2017 · 4 comments

Comments

@kiler129
Copy link
Contributor
kiler129 commented Dec 5, 2017
Q A
Bug report? no (unexpected behavior)
Feature request? yes
BC Break report? no
RFC? no
Symfony version 4.x

While using the DIC component outside of the Symfony I found I need to define my own base_class while calling PhpDumper::dump in order to provide custom functionality. Compiled container indeed contains my class as a parent, however constructor of the class is not called. The generated constructor looks like that:

    public function __construct()
    {
        $this->parameters = $this->getDefaultParameters();

        $this->services = $this->privates = array();
        $this->syntheticIds = array(
            //...
        );
        $this->methodMap = array(
            //...
        );
        $this->aliases = array(
            //...
        );
    }

I checked and this behavior is consistent across 4.0, 3.4 and 3.3 with or without as_files enabled. I guess then the decision was deliberate.

Is there any reason why not to call the base container constructor? WDYT about adding such option?

@kiler129 kiler129 changed the title [DI] Compiled Container Does Not Call Base Class Container [DI] Compiled Container Does Not Call Base Class Constructor Dec 5, 2017
@nicolas-grekas
Copy link
Member

We could add some "initialize" hook that could be called at the end of the constructor, based on a new option to the "dump()" method.
Since you have a use case, you might have want to submit a PR?

@kiler129
Copy link
Contributor Author
kiler129 commented Dec 6, 2017

@nicolas-grekas Sure, I'll work something out probably tomorrow.

@nicolas-grekas
Copy link
Member

I think we make this non-optional: the parent constructor used to be called with a ParameterBag instance previously at the very beginning of the overridden constructor. Let's always call parent::__construct with no arguments. PR welcome.

@xabbuh
Copy link
Member
xabbuh commented Jan 11, 2018

see #25762

nicolas-grekas added a commit that referenced this issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0