Skip to content

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Sep 3, 2025

Q A
Branch? 7.3
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #61612
License MIT

generalized alternative to #61613

@@ -97,7 +97,7 @@ protected function newConstraint(string $name, mixed $options = null): Constrain
return new $className($options['value']);
}

if (array_is_list($options)) {
if (array_is_list($options) || isset($options['value'])) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bit risky if the constraint has a constructor argument named $value.

An alternative solution would be wrapping the call further down in a try catch block like this:

try {
    return new $className(...$options);
} catch (\Error $e) {
    if (str_starts_with($e->getMessage(), 'Unknown named parameter')) {
        return new $className($options);
    }

    throw $e;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in any case, we should deprecate this in 7.4 after merging up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do it the safest way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@xabbuh xabbuh changed the title [Validator] fall back to legacy options handling if the value element is used [Validator] fall back to legacy options handling if configured named arguments do not match Sep 4, 2025
@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit e7c41fe into symfony:7.3 Sep 4, 2025
7 of 11 checks passed
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 4, 2025

Thanks! Follow up welcome on 7.4 🙏

@xabbuh xabbuh deleted the issue-61612 branch September 4, 2025 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants