Closed
Description
Right now, PropertyAccessDecorator treats callable strings as callables, not as strings. Consequently the following code does not behave as expected:
$builder->add('deadline', ChoiceType::class, [
'choices' => $dateRanges, // DateRange objects
'choice_label' => 'end',
]);
This code results in a fatal error. The end()
function exists (is callable), hence the string is not treated as property path. Instead, end()
is called with invalid arguments. IMO there are very few cases where this would be the expected behavior, and even if, it could be solved by passing a closure:
$builder->add('deadline', ChoiceType::class, [
'choices' => $dateRanges, // arrays of dates
'choice_label' => function (array $dateRange) {
return end($dateRange);
},
]);
Treating callable strings as callables should be deprecated. I.e., all methods of PropertyAccessDecorator should trigger deprecation errors if (is_string($value) && is_callable($value))
.
Metadata
Metadata
Assignees
Labels
DX = Developer eXperience (anything that improves the experience of using Symfony)DX = Developer eXperience (anything that improves the experience of using Symfony)Ideal for your first contribution! (some Symfony experience may be required)Ideal for your first contribution! (some Symfony experience may be required)