-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Add InputBag #34363
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
Conversation
b4bce26
to
b6cd87b
Compare
Doesn't the parameter bag have all those fancy |
There's no |
If this is what you're missing, why don't we add those? |
because people are already using this can ( and already does ) cause issues :
works
500 error, should be 400 instead :) |
I understand what you're trying to accomplish. But right now, you're deprecating the only way to access the raw value of an item inside the bag. |
It highly unlikely that you would request raw value, not knowing its type. i suppose we can add |
It might not be the common case, but it has to remain possible. |
Please don't deprecate things that work. Changing for the sake of strictness must be worth the trouble it will incur on the community. |
3f430d6
to
05e0587
Compare
8430bdc
to
ed6c9d8
Compare
@nicolas-grekas @derrabus what are your thoughts about adding more strict validation in the specialized methods like Because right now: // URL: /test?a[]=5&a[]=6
assert(1 === $request->getInt("a")); seems like a bug to me. wdyt? PS: I am not talking about the general |
@apfelbox Those methods simply wrap |
And better if there are |
You should always know what type of input you are expecting, if you are expecting a string, use
In some rare cases, you might be expecting an array or string ( you should probably move to using arrays always in this case ), but you can still do: $input = $request->request->all();
$users = $input['users'];
if (is_string($users)) {
$users = [$users];
}
// $users is known to be an array. If the client passed you the wrong type in production, you will have a deprecation message that you should just ignore, as Symfony 6.0 will throw an exception to the client ( bad request ). |
In the following code
What is the truth ? Is it deprecated for any non-string value or any non-scalar value ? |
@VincentLanglet scalar values can be cast to string when |
Just found a @nicolas-grekas comment
So I assume the phpdoc should be updated |
no, it should still support array as of symfony 5.x, in symfony 6.0 the signature can change to |
If so, the check should be |
it will if |
I used get() for all type of value. I don't know the purpose of this change. It's now breaking all my codes. Please enlighten me or show me a case that why it worth introducing breaking changes. As for the above given example, I cannot figure out your purpose of showing that. But to me, the demo code itself is wrong. Why? because the programmer should always validate the input value and make sure it's the desired data type before calling the search($term) Additionally, sometimes programmer would like to allow front-end submitted value to be either a string or an array, and then handle it differently in the back-end. But after this breaking change, it becomes impossible to do that. |
This ship sailed long ago. As you can see, this has been discussed numerous times 2 years ago, so it's unlikely that the outcome changes now. Furthermore, both deprecation and new behavior has been part of Symfony for nearly 4 years. Changing or reverting now is impossible and will impact more applications than changing this in existing applications that are upgrading to 5.x or 6.x now. Please also do not comment more or less the same things across multiple issues/PRs within the same topic. This divides the same discussion across multiple places, making it harder to track. |
I'm locking all of those issues now. If there's something NEW to discuss, please open a new issue. |
When ppl read a request attribute, they never check if an array is returned
This means many apps just fail with a 500 when adding
[]
in the query string.This PR turns them to 400 basically (with a deprecation for now)