diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php index 728332ceaf..c8978f377f 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php @@ -79,7 +79,7 @@ class CheckDefinitionValidityPass implements CompilerPassInterface foreach ($definition->getTags() as $name => $tags) { foreach ($tags as $attributes) { foreach ($attributes as $attribute => $value) { - if (!is_scalar($value)) { + if (!is_scalar($value) && null !== $value) { throw new RuntimeException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $id, $name, $attribute)); } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 21314b0b11..11e94c8c40 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -224,7 +224,7 @@ class YamlFileLoader extends FileLoader unset($tag['name']); foreach ($tag as $attribute => $value) { - if (!is_scalar($value)) { + if (!is_scalar($value) && null !== $value) { throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s.', $id, $name, $attribute, $file)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php index 2580318a08..b5e49842e7 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php @@ -61,6 +61,17 @@ class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase $this->process($container); } + public function testValidTags() + { + $container = new ContainerBuilder(); + $container->register('a', 'class')->addTag('foo', array('bar' => 'baz')); + $container->register('b', 'class')->addTag('foo', array('bar' => null)); + $container->register('c', 'class')->addTag('foo', array('bar' => 1)); + $container->register('d', 'class')->addTag('foo', array('bar' => 1.1)); + + $this->process($container); + } + /** * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */