8000 bug #20539 Cast result to int before adding to it (alcaeus) · symfony/symfony@28a0be8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28a0be8

Browse files
bug #20539 Cast result to int before adding to it (alcaeus)
This PR was merged into the 2.7 branch. Discussion ---------- Cast result to int before adding to it | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This fixes the occasional warning about non-numeric values when using PHP 7.1. Commits ------- 70c42f2 Cast result to int before adding to it
2 parents be5a5e4 + 70c42f2 commit 28a0be8

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,22 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
346346
$arg->setAttribute('key', $arg->getAttribute('name'));
347347
}
348348

349-
if (!$arg->hasAttribute('key')) {
350-
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
351-
} else {
352-
$key = $arg->getAttribute('key');
353-
}
354-
355-
// parameter keys are case insensitive
356-
if ('parameter' == $name && $lowercase) {
357-
$key = strtolower($key);
358-
}
359-
360349
// this is used by DefinitionDecorator to overwrite a specific
361350
// argument of the parent definition
362351
if ($arg->hasAttribute('index')) {
363352
$key = 'index_'.$arg->getAttribute('index');
353+
} elseif (!$arg->hasAttribute('key')) {
354+
// Append an empty argument, then fetch its key to overwrite it later
355+
$arguments[] = null;
356+
$keys = array_keys($arguments);
357+
$key = array_pop($keys);
358+
} else {
359+
$key = $arg->getAttribute('key');
360+
361+
// parameter keys are case insensitive
362+
if ('parameter' == $name && $lowercase) {
363+
$key = strtolower($key);
364+
}
364365
}
365366

366367
switch ($arg->getAttribute('type')) {
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', 'bar'), $container->getDefinition('foo')->getArguments());
553+
}
545554
}

0 commit comments

Comments
 (0)
0