Skip to content

[DI] Fixed index args bug with ResolveNamedArgumentsPass #22677

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
May 9, 2017

Conversation

weaverryan
Copy link
Member

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR n/a

While upgrading a project, this code suddenly broke:

services:
    ice_cream_service:
        class: AppBundle\Service\IceCreamService
        autowire: true
        arguments:
            1: 'http://api.example.com'
class IceCreamService
{
    public function __construct(EntityManager $em, $apiUrl)
    {
    }
}

Suddenly, the index 1 was not being mapped to $apiUrl. This was valid in 3.2, but broke when ResolveNamedArgumentsPass accidentally re-set the index. Simple fix :). Ping @dunglas

Cheers!

@dunglas
Copy link
Member

dunglas commented May 9, 2017

@weaverryan didn't we decide to deprecate the use of keys not starting with a $? #21383 (comment)

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

👍 anyway ok for me

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

👍 ... but @dunglas comment is important: did you agree to deprecate this feature?

@fabpot
Copy link
Member

fabpot commented May 9, 2017

Thank you @weaverryan.

@fabpot fabpot merged commit 7cc7c85 into symfony:master May 9, 2017
fabpot added a commit that referenced this pull request May 9, 2017
…weaverryan)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Fixed index args bug with ResolveNamedArgumentsPass

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | n/a

While upgrading a project, this code suddenly broke:

```yml
services:
    ice_cream_service:
        class: AppBundle\Service\IceCreamService
        autowire: true
        arguments:
            1: 'http://api.example.com'
```

```php
class IceCreamService
{
    public function __construct(EntityManager $em, $apiUrl)
    {
    }
}
```

Suddenly, the index `1` was not being mapped to `$apiUrl`. This was valid in 3.2, but broke when `ResolveNamedArgumentsPass` accidentally re-set the index. Simple fix :). Ping @dunglas

Cheers!

Commits
-------

7cc7c85 Fixing bug where indexed args were set wrong in pass in some situations
@nicolas-grekas
Copy link
Member

@GuilhemN I remember we looked at that together also if I'm not wrong? Any comment here?

@GuilhemN
Copy link
Contributor

GuilhemN commented May 9, 2017

We talked about it in #21700 and on slack but I can't recover our discussion... If I remember well your argument was that it has never been a supported use case and it only worked by chance for autowiring. For example, the following didn't behave the way described in this pr:

services:
    ice_cream_service:
        class: AppBundle\Service\IceCreamService
        autowire: true
        arguments:
            2: 'bar'
            1: 'http://api.example.com'

I'm not against this change but it probably requires a patch in older versions.

@weaverryan weaverryan deleted the named-args-index-args-fix branch May 9, 2017 20:10
@weaverryan
Copy link
Member Author

About deprecating specific indexed args, I don't know what we might have agreed on, but I certainly think it makes sense. Let's make a PR for 3.4.

But, for 3.2, using indexed args WAS a valid way of doing things... I actually would teach it that way (I even thought it was doc'ed, but it's not). So, I think this correctly merged (to keep BC) and we can definitely deprecate for 3.4 - named args are WAY better :).

@fabpot fabpot mentioned this pull request May 17, 2017
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.

7 participants