-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Fix using known option names as field names #53133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Validator] Fix using known option names as field names #53133
Conversation
$knowOptions = array_map(function (\ReflectionParameter $parameter) { | ||
return $parameter->name; | ||
}, (new \ReflectionMethod(__METHOD__))->getParameters()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$knowOptions = array_map(function (\ReflectionParameter $parameter) { | |
return $parameter->name; | |
}, (new \ReflectionMethod(__METHOD__))->getParameters()); | |
static $knowOptions; | |
$knownOptions ??= array_column((new \ReflectionMethod(__METHOD__))->getParameters(), 'name'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I had to adjust the code for PHP 7.2. I'm wondering, is the static variable necessary since this all happens in the constructor?
e92d8a1
to
51d1960
Compare
51d1960
to
51ec528
Compare
Thank you @HypeMC. |
Fyi, this breaks code where |
This PR was merged into the 5.4 branch. Discussion ---------- [Validator] re-allow an empty list of fields | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #53133 (comment) | License | MIT Commits ------- 098c14c re-allow an empty list of fields
This PR was merged into the 5.4 branch. Discussion ---------- [Validator] re-allow an empty list of fields | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony/symfony#53133 (comment) | License | MIT Commits ------- 098c14cc92 re-allow an empty list of fields
I tried this (#53383) fix and it still breaks for an empty list of constraints, which I confirmed was working in
For my use case I can mitigate this by using
|
just had the same problem as @dresslerdemos |
I have a fix pending locally. I’ll keep you posted. |
@dresslerdemos @nerones Can you check if #53443 fixes it for you? |
… (xabbuh, HypeMC) This PR was merged into the 5.4 branch. Discussion ---------- [Validator] Fix fields without constraints in `Collection` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #53133 (comment), Fix #53455 | License | MIT Continuation of #53443. Commits ------- f6217d8 [Validator] Fix fields without constraints in `Collection` b341535 deal with fields for which no constraints have been configured
… (xabbuh, HypeMC) This PR was merged into the 5.4 branch. Discussion ---------- [Validator] Fix fields without constraints in `Collection` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony/symfony#53133 (comment), Fix #53455 | License | MIT Continuation of #53443. Commits ------- f6217d87e6 [Validator] Fix fields without constraints in `Collection` b341535558 deal with fields for which no constraints have been configured
Instead of assuming
$fields
is not the fields array when any of the keys is a known option, let's assume it is the fields array if all keys are known options. Of course, this approach won't work if someone names all their fields after known options, but I don't believe that will actually happen.