diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 394462150d..03beff4d31 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -37,7 +37,7 @@ class ChoiceType extends AbstractType throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface".'); } - if (!$options['choice_list'] && !$options['choices']) { + if (!$options['choice_list'] && !is_array($options['choices']) && !$options['choices'] instanceof \Traversable) { throw new FormException('Either the option "choices" or "choice_list" must be set.'); } diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php index e30839a041..01ea4bf911 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php @@ -662,4 +662,12 @@ class ChoiceTypeTest extends TypeTestCase $this->assertSame('name[]', $view->get('full_name')); } + + // https://github.com/symfony/symfony/issues/3298 + public function testInitializeWithEmptyChoices() + { + $this->factory->createNamed('choice', 'name', null, array( + 'choices' => array(), + )); + } }