Skip to content

PropertyAccessDecorator should not accept callable strings #17993

Closed
@webmozart

Description

@webmozart

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

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)FormGood first issueIdeal for your first contribution! (some Symfony experience may be required)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions