Skip to content

Fix serialization of array values in query string parameters#46

Open
aivus wants to merge 1 commit into
masterfrom
array-query-params-master
Open

Fix serialization of array values in query string parameters#46
aivus wants to merge 1 commit into
masterfrom
array-query-params-master

Conversation

@aivus

@aivus aivus commented Jul 7, 2026

Copy link
Copy Markdown
Member

Problem

RequestFactory::getRequestUri() substitutes every query placeholder with urlencode((string)$value). When a request DTO getter returns an array (e.g. getCategories(): ?array for an endpoint path like /list?categories={categories}), the string cast produces the literal value Array in the request URI (plus a PHP notice), so array query parameters cannot be sent at all.

Fix

  • Array values for query placeholders are now serialized with http_build_query(), replacing the whole name={placeholder} pair. This expands to bracket syntax (categories%5B0%5D=a&categories%5B1%5D=b), which PHP servers natively parse back into arrays via $request->query->all().
  • An empty array drops the parameter from the query string entirely; a new normalizeQueryString() helper cleans up leftover && / ?& / trailing separators.
  • Scalar and null values keep the exact previous behavior — no backward-compatibility impact.

Tests

Added RequestFactoryTest cases covering: multi-value arrays expanding to bracket syntax, urlencoding of array items, empty arrays being dropped (first, middle, and only-parameter positions, including no trailing ?). Full suite: 95 tests, 255 assertions, green on PHP 7.4.

🤖 Generated with Claude Code

RequestFactory cast every query placeholder value to string, so an
array value produced the literal "Array" in the request URI. Serialize
arrays with http_build_query() instead, expanding them to bracket
syntax (param[0]=a&param[1]=b). Empty arrays drop the parameter
entirely, with leftover query separators cleaned up.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant