-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] fix Catchable Fatal Error if choices is not an array #17163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The choice list normalizer does this: // Harden against NULL values (like in EntityType and ModelType)
$choices = null !== $options['choices'] ? $options['choices'] : array(); What about using the same here? |
If the choicesNormalizer have to make an array in every case, you're right. |
@webmozart @nicolas-grekas Depends on: |
👍 |
'expanded' => false, | ||
'choices' => null, | ||
)); | ||
$this->assertEquals($form->getConfig()->getOption('choices'), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure but I think assertEquals
doesn't make a strict comparison. An assertion will be considered valid if you receive false
whereas you expect null
(and vice-versa). I suggest to use the proper assertion methods instead for both readability and strict comparison.
$this->assertNull($form->getConfig()->getOption('choices'));
$this->assertFalse($form->getConfig()->getOption('multiple'));
$this->assertFalse($form->getConfig()->getOption('expanded'));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change this as you wish.
Surely checking if is null is more correct? If something else is passed that's not null or an array, we want the type error to happen, right? |
@nicolas-grekas done |
@Gladhon it looks like the phpdoc block wasn't formatted correctly (see fabbot's patch) can you please fix it and also squash all the commits in one? |
Thank you @Gladhon. |
…y (Gladhon, nicolas-grekas) This PR was merged into the 2.7 branch. Discussion ---------- [Form] fix Catchable Fatal Error if choices is not an array | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | Since 2.7.8 I got a BC-Break Error Catchable Fatal Error: Argument 1 passed to Symfony\Component\Form\Extension\Core\Type\ChoiceType::normalizeLegacyChoices() must be of the type array, null given normalizeLegacyChoices work only with array, so if choices not an array, just don't try to normlize. Commits ------- f3c2a9b [Form] fix Catchable Fatal Error if choices is not an array
Since 2.7.8 I got a BC-Break Error
Catchable Fatal Error: Argument 1 passed to Symfony\Component\Form\Extension\Core\Type\ChoiceType::normalizeLegacyChoices() must be of the type array, null given
normalizeLegacyChoices work only with array, so if choices not an array, just don't try to normlize.