diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php index 5f0d93711af24..e45db82d837df 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php @@ -182,10 +182,11 @@ protected function processValue($value, bool $isRoot = false) foreach ($reflectionMethod->getParameters() as $key => $parameter) { $names[$key] = $parameter->name; - if (\array_key_exists($key, $arguments) && '' !== $arguments[$key]) { - continue; + if (\array_key_exists($parameter->name, $arguments)) { + $key = $parameter->name; } - if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name]) { + + if (\array_key_exists($key, $arguments) && !\in_array($arguments[$key], ['', null, []], true)) { continue; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php index 600c8e036c4cd..a7f8d6f736ca9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php @@ -213,6 +213,32 @@ public function testEmptyBindingTypehint() $pass->process($container); } + /** + * @testWith [1, ""] + * [1, null] + * [1, []] + * ["apiKey", ""] + * ["apiKey", null] + * ["apiKey", []] + */ + public function testEmptyBindingWithEmptyDefaultValue($key, $value) + { + $container = new ContainerBuilder(); + + $bindings = [ + '$apiKey' => new BoundArgument('foo'), + ]; + + $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); + $definition->setArguments([$key => $value]); + $definition->setBindings($bindings); + + $pass = new ResolveBindingsPass(); + $pass->process($container); + + $this->assertEquals([$key => 'foo'], $definition->getArguments()); + } + public function testIterableBindingTypehint() { $autoloader = static function ($class) {