Skip to content

[Validator] Creating constraint with options in array after using array_walk #20106

Closed
@surypavel

Description

@surypavel

Hello! I found out about a rather unexpected interaction. This code doesn't work, throwing an ConstraintDefinitionException (No default option is configured for constraint):

$options = ['message'=>'Hello'];
array_walk($options, function(&$item) { $item = $item . ' world!'; });
$constraint = new Email($options); // Not working

In order to make it work, I have to use reset($options) after array_walk() so that I get a valid array pointer. I propose to either output a meaningful error message (that Constraint cannot be initialized without valid internal pointer) or to replace is_string(key($options)) in Symfony\Component\Validator\Constraint to something like is_string(array_keys($options)[0]).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions