diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php index fcccfdd0bd..4fbca4b451 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php @@ -261,7 +261,7 @@ class ChoiceList implements ChoiceListInterface { // Add choices to the nested buckets foreach ($choices as $group => $choice) { - if (!isset($labels[$group])) { + if (!array_key_exists($group, $labels)) { throw new \InvalidArgumentException('The structures of the choices and labels array do not match.'); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php index 86533e8af8..7e967924d3 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php @@ -184,4 +184,20 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase array('A') ); } + + /** + * test for pull request: https://github.com/symfony/symfony/pull/5394 + */ + public function testLabelsContainingNull() + { + $this->list = new ChoiceList( + array($this->obj1, $this->obj2), + array('A', null) + ); + + $this->assertEquals( + array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', null)), + $this->list->getRemainingViews() + ); + } }