Closed
Description
Symfony version(s) affected
6.0.6
Description
When I do create a Form and execute the following code:
$parsedErrors = [];
$errors = $form->getErrors(true);
while($errors->current() !== null) {
$parsedErrors[] = $errors->current();
$errors->next();
}
It crashes with following message
Return value must be of type Symfony\Component\Form\FormError|Symfony\Component\Form\FormErrorIterator, bool returned
How to reproduce
Aside note: my project is an API
Inside a project create a Form and send to it an invalid data with a POST request so the error bad will be filled and the $form->getErrors(true)
should not be empty.
Then run code that looks like this:
$parsedErrors = [];
$errors = $form->getErrors(true);
while($errors->current() !== null) {
$parsedErrors[] = $errors->current();
$errors->next();
}
And web server will throw a 502 http code with critical log at PHP FPM container (I do use docker)
Possible Solution
For newer version of PHP there are union types, in PHP8 they works like that
public function x(): int|float
{
return [
5, 1.2
][rand(0,1)];
}
So adding an bool to the return type of Symfony\Component\Form\FormErrorIterator::current() should be sufficient
Additional Context
No response