10BC0 [DI] Cannot override parent with named arguments · Issue #22196 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Cannot override parent with named arguments #22196

@ro0NL

Description

@ro0NL
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0