Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

PropertyAccessDecorator should not accept callable strings #17993

Copy link
Copy link
Closed
@webmozart

Description

@webmozart
Issue body actions

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)DX = Developer eXperience (anything that improves the experience of using Symfony)FormGood first issueIdeal for your first contribution! (some Symfony experience may be required)Ideal 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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.