diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 703620c8a67e..2da8347a4bba 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -736,7 +736,7 @@ private function resolveServices($value, $file, $isParameter = false) throw new InvalidArgumentException(sprintf('"!%s" tag contains unsupported key "%s"; supported ones are "tag", "index_by" and "default_index_method".', $value->getTag(), implode('"", "', $diff))); } - $argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'], $argument['default_index_method'] ?? null, $forLocator); + $argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'] ?? null, $argument['default_index_method'] ?? null, $forLocator); if ($forLocator) { $argument = new ServiceLocatorArgument($argument); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/tagged_iterator_optional.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/tagged_iterator_optional.yml new file mode 100644 index 000000000000..6c6b65226dd2 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/tagged_iterator_optional.yml @@ -0,0 +1,4 @@ +services: + iterator_service: + class: FooClass + arguments: [!tagged {tag: test.tag}] diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 0207abadec71..c0291c76c76d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -852,4 +852,18 @@ public function testOverriddenDefaultsBindings() $this->assertSame('overridden', $container->get('bar')->quz); } + + /** + * When creating a tagged iterator using the array syntax, all optional parameters should be properly handled. + */ + public function testDefaultValueOfTagged() + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('tagged_iterator_optional.yml'); + + $iteratorArgument = $container->getDefinition('iterator_service')->getArgument(0); + $this->assertInstanceOf(TaggedIteratorArgument::class, $iteratorArgument); + $this->assertNull($iteratorArgument->getIndexAttribute()); + } }