Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Autowiring skips scalars, confuses order #17878

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
weaverryan opened this issue Feb 22, 2016 · 1 comment
Closed

Autowiring skips scalars, confuses order #17878

weaverryan opened this issue Feb 22, 2016 · 1 comment

Comments

@weaverryan
Copy link
Member

This somewhat relates to #17724

Take this class:

class ArgumentWithNoTypeHint
{
    public function __construct(A $a, $foo, Lille $l)
    {
    }
}

Currently, since $foo is not type-hinted, it just skips filling it in. Because of this, $definition->getArguments() returns 2 items with indexes 0 and 2. But the container ultimately passes these as arguments 1 and 2. The error here would be:

Argument 3 passed to ArgumentWithNoTypeHint must be an instance of Lille, none given.

@weaverryan
Copy link
Member Author

See #17876 for the fix

fabpot added a commit that referenced this issue Mar 1, 2016
… are set (weaverryan)

This PR was merged into the 2.8 branch.

Discussion
----------

[DependencyInjection] Fixing autowiring bug when some args are set

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17724, #17878
| License       | MIT
| Doc PR        | todo

This fixes #17724 & #17878.

**#17724**

I've set this against the 2.8 branch because imo it's a bug fix. The [test](https://github.com/symfony/symfony/compare/2.8...weaverryan:auto-wiring-individuals?expand=1#diff-d124c3d39cd5f7c732fb3d3be7a8cb42R298) illustrates the bug - having *some* arguments set beforehand caused auto-wired arguments to be set on the wrong index.

**#17878**

I've also included this fix just to get all the weird ordering problems taken care of at once. I don't think this is a behavior change - autowiring with scalars only worked previously if the argument was optional (still works now) or if you specified that argument explicitly (still works). Otherwise, your argument ordering would have gotten messed up.

Commits
-------

260731b minor changes
865f202 [#17878] Fixing a bug where scalar values caused invalid ordering
cf692a6 [#17724] Fixing autowiring bug where if some args are set, new ones are put in the wrong spot
@fabpot fabpot closed this as completed Mar 1, 2016
fabpot added a commit that referenced this issue Mar 1, 2016
* 2.8:
  fixed issue with PHP 5.3
  The WebProcessor now forwards the client IP
  minor changes
  [#17878] Fixing a bug where scalar values caused invalid ordering
  [#17724] Fixing autowiring bug where if some args are set, new ones are put in the wrong spot
  bumped Symfony version to 2.3.39
  updated VERSION for 2.3.38
  update CONTRIBUTORS for 2.3.38
  updated CHANGELOG for 2.3.38
fabpot added a commit that referenced this issue Mar 1, 2016
* 3.0:
  fixed issue with PHP 5.3
  The WebProcessor now forwards the client IP
  minor changes
  [#17878] Fixing a bug where scalar values caused invalid ordering
  [#17724] Fixing autowiring bug where if some args are set, new ones are put in the wrong spot
  bumped Symfony version to 2.3.39
  updated VERSION for 2.3.38
  update CONTRIBUTORS for 2.3.38
  updated CHANGELOG for 2.3.38
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