Problem/Motivation
When upgrading to Symfony 5.4 various tests throw deprecation warnings:
Since symfony/http-foundation 5.1: Passing a non-scalar value as 2nd argument to "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated, pass a scalar or null instead.
Since symfony/http-foundation 5.1: Retrieving a non-string value from "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated, and will throw a "Symfony\Component\HttpFoundation\Exception\BadRequestException" exception in Symfony 6.0, use "Symfony\Component\HttpFoundation\InputBag::all($key)" instead.
In #3162016: [Symfony 6] Retrieving a non-string value from "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated we first approached this problem but then the first solution was rolled back, a simpler solution was implemented, but the remainder of the changes were not committed in that issue.
Steps to reproduce
Proposed resolution
Reuse code from #3162016: [Symfony 6] Retrieving a non-string value from "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated that was not committed.
Use $request->query->all(...)
when retrieving an array.
Use $request->query->get(...)
when retrieving a scalar.
Use $request->query->all()[...]
when retrieving either an array or scalar and the subsequent code can handle both types.
Where the query isn't guaranteed to be set, start using $request->query->has()
.
User interface changes
no
API changes
no
Data model changes
no
Release notes snippet
no