-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] empty_data in ChoiceType can be a string what must not be called #25896
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
Comments
You are right. But I don't see what we can do here without break BC. The solution for you would be to pass an anonymous function that just returns the string. |
In other places, we deprecated the ability to pass callables as string to avoid such issues. That's something we could do here in 4.1 too so that we can remove support for it in 5.0. |
@xabbuh Do we still have more places like that? That sounds like an ugly pitfall in general. |
I think it's very likely that we have similar code in other places. |
@peter-gribanov I totally agree about I'm not sure about |
@derrabus it may seem absurd, but it's still possible. This code seems innocuous: $builder->add('body', ChoiceType::class, array(
'attr' => ['title' => 'sum'],
)); But everything can turn out to be very unexpected if the project has such class: class Title
{
public static function sum($x, $y)
{
return sprintf('Sum x + y = %d', $x + $y);
}
} |
@peter-gribanov No, because to call the class in your example, the array would be |
@derrabus exactly. sorry 🙇 |
…e (HeahDude) This PR was merged into the 2.7 branch. Discussion ---------- [Form] Fixed empty data on expanded ChoiceType and FileType | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25896 | License | MIT | Doc PR | ~ Alternative of #25924. I don't think we have to do this by adding overhead in master and getting it properly fixed in 2 years. This is bug I've introduced while fixing another bug #17822. Which then has been replicated in #20418 and #24993. I propose instead to clean up the code for all LTS, since this is a wrong behaviour that has never been documented, and most of all unreliable. The `empty_data` can by anything in the view format as long as the reverse view transformation supports it. Even an object derived from the data class could be invokable. I think we should remain consistent with https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Form.php#L615. Commits ------- 9722c06 [Form] Fixed empty data on expanded ChoiceType and FileType
Example problem:
In this case, i get an error at this line:
The text was updated successfully, but these errors were encountered: