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

[DI] Cannot override parent with named arguments #22196

Closed
ro0NL opened this issue Mar 28, 2017 · 1 comment
Closed

[DI] Cannot override parent with named arguments #22196

ro0NL opened this issue Mar 28, 2017 · 1 comment

Comments

@ro0NL
Copy link
Contributor

ro0NL commented Mar 28, 2017

Q A
Bug report? yes
Feature request? yes
BC Break report? no
Symfony version 3.x

Given

services:
    AppBundle\Foo: [a, b]
    foo:
        parent: AppBundle\Foo
        arguments: { '$b': b_custom }

I get

ContextErrorException in ResolveDefinitionTemplatesPass.php line 173:
Notice: Undefined variable: index

I checked it out and tried a quick patch

diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
index 9cc2250..b3856b2 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
@@ -166,7 +166,9 @@ class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
 
             if (0 === strpos($k, 'index_')) {
                 $index = (int) substr($k, strlen('index_'));
-            } elseif (0 !== strpos($k, '$')) {
+            } elseif (0 === strpos($k, '$')) {
+                $index = $k;
+            } else {
                 throw new RuntimeException(sprintf('Invalid argument key "%s" found.', $k));
             }

No luck

OutOfBoundsException in Definition.php line 214:
Service "foo": The argument "$b" doesn't exist.

Kind of a feature request, but certainly an expected one if you ask me.

@nicolas-grekas
Copy link
Member

Should be fixed by #22358

@nicolas-grekas nicolas-grekas removed their assignment Apr 10, 2017
fabpot added a commit that referenced this issue Apr 10, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Fix named args overridding

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

(The exception check in ResolveDefinitionTemplatesPass is not done in ResolveNamedArgumentsPass.)

Commits
-------

0c030d9 [DI] Fix named args overridding
@fabpot fabpot closed this as completed Apr 10, 2017
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

4 participants