Skip to content

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Apr 29, 2017

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

Follow up of #22511, from @iltar:

Currently, when having a service definition which has more than 1 usage of that service, it will put the argument in $a for example. By doing so, it will also use $a in the callable of the ServiceLocator, which result in an undefined variable $a.

I managed to trigger this with the translator service, where I have my own loader, that I add for NL and EN, causing 2 method calls to turn the direct getter into a variable. I've added 2 test cases, 1 with only 1 method call and 1 with 2 method calls.

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Apr 29, 2017
@nicolas-grekas nicolas-grekas changed the title Di fix vars [DI] Fix invalid callables dumped for ArgumentInterface objects Apr 29, 2017
@nicolas-grekas
Copy link
Member Author

Diff best reviewed ignoring whitespaces: https://github.com/symfony/symfony/pull/22581/files?w=1
Patch made to minimize any future merge conflicts with 3.2.

} elseif ($value instanceof ServiceClosureArgument) {
$value = $value->getValues()[0];
$code = $this->dumpValue($value, $interpolate);
} elseif ($scope = $value instanceof ArgumentInterface) {
Copy link
Member

Choose a reason for hiding this comment

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

should just be if as the previous if returns

$value = $value->getValues()[0];
$code = $this->dumpValue($value, $interpolate);
} elseif ($scope = $value instanceof ArgumentInterface) {
$scope = array($this->definitionVariables, $this->referenceVariables, $this->variableCount);
Copy link
Member

Choose a reason for hiding this comment

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

Reusing the same variable to store a boolean or an array is harder to follow. Can't we put the try/finally inside this if instead, which will allow to only store an array in $scope ?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, PR should be OK

@nicolas-grekas
Copy link
Member Author

Thank you @iltar.

@nicolas-grekas nicolas-grekas merged commit f81c577 into symfony:master Apr 30, 2017
nicolas-grekas added a commit that referenced this pull request Apr 30, 2017
…jects (nicolas-grekas, iltar)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Fix invalid callables dumped for ArgumentInterface objects

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

Follow up of #22511, from @iltar:

> Currently, when having a service definition which has more than 1 usage of that service, it will put the argument in `$a` for example. By doing so, it will also use `$a` in the callable of the `ServiceLocator`, which result in an undefined variable `$a`.

> I managed to trigger this with the translator service, where I have my own loader, that I add for NL and EN, causing 2 method calls to turn the direct getter into a variable. I've added 2 test cases, 1 with only 1 method call and 1 with 2 method calls.

Commits
-------

f81c577 [DI] Test references inside ServiceLocator are not inlined
8783602 [DI] Fix invalid callables dumped for ArgumentInterface objects
@nicolas-grekas nicolas-grekas deleted the di-fix-vars branch April 30, 2017 10:57
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.

3 participants