Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] Fixing autowiring bug when some args are set#17876

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 3 commits intosymfony:2.8fromweaverryan:auto-wiring-individuals
Mar 1, 2016

Conversation

@weaverryan
Copy link
Member

QA
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#17724,#17878
LicenseMIT
Doc PRtodo

Thisfixes#17724 &#17878.

#17724

I've set this against the 2.8 branch because imo it's a bug fix. Thetest illustrates the bug - havingsome 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.

@weaverryanweaverryan changed the title[#17724] Fixing autowiring bug where if some args are set, new ones a…[DependencyInjection] Fixing autowiring bug when some args are setFeb 21, 2016
@weaverryanweaverryanforce-pushed theauto-wiring-individuals branch 2 times, most recently from2a8bd95 to8a50a2cCompareFebruary 22, 2016 01:18
publicfunction__construct(A$a,$foo ='default_val',Lille$lille)
{
}
}
Copy link
Member

Choose a reason for hiding this comment

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

New line

@dunglas
Copy link
Member

👍

Just a minor thing, this blockhttps://github.com/weaverryan/symfony/blob/auto-wiring-individuals/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php#L74-L77 can now be inlined (the$argumentExists variable is not needed anymore).

Thank for fixing this!

}

// specifically pass the default value
$arguments[$index] =$parameter->getDefaultValue();
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to omit the default value when no required parameter without a default values is following. PHP populates how many arguments the user passed to a method/constructor (we use this in some places when method parameters get deprecated asfunc_num_args() exposes the number of arguments passed by the caller).

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We can do this, but it's tricky. For example:

publicfunction __construct($foo ='foo',LoggerInterface$logger =null)

In this case,$foo is optional. If we omit it but then$logger becomes mapped because of autowiring, we suddenlywill need to pass the$foo value. This means we'll need to not set optional values here, but keep track of them and add them at the end if we detect that they are suddenly needed. Does that make sense? I was waiting to see if anyone asked about this.

Copy link
Member

Choose a reason for hiding this comment

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

Your current implementation is easier to read and maintain. Anyway, it's probably a bad idea to use autowiring for classes using tricks like the one withfunc_num_args().

@weaverryan
Copy link
MemberAuthor

Ping @symfony/deciders - failure on appveyor is unrelated :)

@fabpot
Copy link
Member

Thank you@weaverryan.

@fabpotfabpot merged commit260731b intosymfony:2.8Mar 1, 2016
fabpot added a commit that referenced this pull requestMar 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        | todoThisfixes#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 changes865f202 [#17878] Fixing a bug where scalar values caused invalid orderingcf692a6 [#17724] Fixing autowiring bug where if some args are set, new ones are put in the wrong spot
This was referencedMar 27, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@weaverryan@dunglas@fabpot@javiereguiluz@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp