Skip to content
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

[DependencyInjection] check for circular refs caused by method calls #21642

Closed
wants to merge 1 commit into from

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Feb 17, 2017

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

@xabbuh
Copy link
Member Author

xabbuh commented Feb 17, 2017

Tests pass on master too now (see https://travis-ci.org/symfony/symfony/builds/202523603) thanks to the changes @nicolas-grekas made in #21639.

;

$container
->register('foo', '\stdClass')
Copy link
Contributor

Choose a reason for hiding this comment

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

should be bar no?

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, good catch

Copy link
Contributor

Choose a reason for hiding this comment

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

isn't it weird the tests still passed with that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, a circular reference is still a circular reference. I just wanted to explicitly have one with an intermediate service.

$instance->setFoo($this->get('foo_with_inline'));

return $instance;
return $this->services['baz'] = new \Baz();
Copy link
Member

Choose a reason for hiding this comment

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

This was a case where the circular reference was working, as the service can be instantiated and registered in $this->services before the point triggering the call to the other service, meaning it will receive the instance.
Forbidding a case which was working previously is a BC break. So this is not acceptable, especially for a patch release

@stof
Copy link
Member

stof commented Feb 17, 2017

-1 for this PR as is. It removes a supported feature. Tests are passing now because you remove the test ensuring that this feature keeps working

@stof
Copy link
Member

stof commented Feb 17, 2017

And given the potential to break existing projects, should we really merge this again in a patch release ? Our latest releases already have a BC break because of this.

@theofidry
Copy link
Contributor

theofidry commented Feb 17, 2017

@xabbuh tbh I fail to see how this circular dependency is a problem in the first place, it sure can be a big smell, but it's a legitimate thing as well. For example if you have:

class X {
  private $y;

  setY(self $y) {
    $this->y = $y;
  }
}

$x1 = new X();
$x2 = new X();

$x1->setY($x2);
$x2->setY($x1);

it's perfectly ok in PHP, I don't see why you shouldn't be able to do this with the DIC. There is legitimate use cases for it (I don't have on top of my head though soz)

@xabbuh
Copy link
Member Author

xabbuh commented Feb 17, 2017

Our latest releases already have a BC break because of this.

@stof I don't know what you mean. The commit that reverted the previous PR (68d6415) was part of the 3.2.4 release.

@stof
Copy link
Member

stof commented Feb 17, 2017

@xabbuh see my comment in the issue giving more details about the work needed. This PR as is is not the right fix (it has false positives, which are worse than false negatives)

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Feb 18, 2017
@xabbuh
Copy link
Member Author

xabbuh commented Apr 3, 2017

Closing as this is not the solution for the problem. But we still have #19362 that reminds us of the real issue.

@xabbuh xabbuh closed this Apr 3, 2017
@xabbuh xabbuh deleted the issue-19362 branch April 3, 2017 10:11
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.

None yet

5 participants