8000 Cast result to int before adding to it · symfony/symfony@9f9e8ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f9e8ab

Browse files
committed
Cast result to int before adding to it
This fixes the occasional warning about non-numeric values when using PHP 7.1
1 parent ef40651 commit 9f9e8ab

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
347347
}
348348

349349
if (!$arg->hasAttribute('key')) {
350-
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
350+
$key = !$arguments ? 0 : (int) max(array_keys($arguments)) + 1;
351351
} else {
352352
$key = $arg->getAttribute('key');
353353
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="foo" class="Foo">
5+
<argument key="type">foo</argument>
6+
<argument>bar</argument>
7+
</service>
8+
</services>
9+
</container>

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,13 @@ public function testLoadInlinedServices()
542542
$this->assertSame('Baz', $barConfigurator[0]->getClass());
543543
$this->assertSame('configureBar', $barConfigurator[1]);
544544
}
545+
546+
public function testArgumentWithKeyOutsideCollection()
547+
{
548+
$container = new ContainerBuilder();
549+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
550+
$loader->load('with_key_outside_collection.xml');
551+
552+
$this->assertSame(array('type' => 'foo', 1 => 'bar'), $container->getDefinition('foo')->getArguments());
553+
}
545554
}

0 commit comments

Comments
 (0)
0