Skip to content

Commit 4f47e8d

Browse files
committed
minor #16865 Change recommended way to access array query string parameters (jontjs, Jon Green)
This PR was submitted for the 6.1 branch but it was merged into the 6.0 branch instead. Discussion ---------- Change recommended way to access array query string parameters `$request->query->all()['foo'];` triggers an 'Undefined array key "foo"' error when `foo` doesn't exist. However `$request->query->all('foo');` return null when `foo` doesn't exist (consistent with `$request->query->get('bar');` for accessing a string parameter `bar` which might not exist). <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `6.x` for features of unreleased versions). --> Commits ------- 320a501 Update http_foundation.rst 29e1c0e Update http_foundation.rst
2 parents 1a82990 + 320a501 commit 4f47e8d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

components/http_foundation.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,13 @@ doesn't support returning arrays, so you need to use the following code::
169169
// the query string is '?foo[bar]=baz'
170170

171171
// don't use $request->query->get('foo'); use the following instead:
172-
$request->query->all()['foo'];
172+
$request->query->all('foo');
173173
// returns ['bar' => 'baz']
174174

175+
// if the requested parameter does not exist, an empty array is returned:
176+
$request->query->all('qux');
177+
// returns []
178+
175179
$request->query->get('foo[bar]');
176180
// returns null
177181

0 commit comments

Comments
 (0)