[Form] fix Catchable Fatal Error if choices is not an array#17163
[Form] fix Catchable Fatal Error if choices is not an array#17163Gladhon wants to merge 1 commit intosymfony:2.7from Gladhon:2.7
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: |
|
👍 |
There was a problem hiding this comment.
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.
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.