php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67008 http_build_query() doesn't properly handle array without keys
Submitted: 2014-04-03 03:08 UTC Modified: -
Votes:9
Avg. Score:3.9 ± 1.3
Reproduced:8 of 8 (100.0%)
Same Version:1 (12.5%)
Same OS:3 (37.5%)
From: chuanm at gmail dot com Assigned:
Status: Open Package: HTTP related
PHP Version: 5.4.26 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chuanm at gmail dot com
New email:
PHP Version: OS:

 

 [2014-04-03 03:08 UTC] chuanm at gmail dot com
Description:
------------
Given an array without index, http_build_query() adds numeric index 0, 1, 2,... in its output. This is working if the web server is php, but fails to work when I use php curl functions to send the array to a rails server. Rails server treats this as a hash (with the added index in http_build_query() output).

Test script:
---------------
<?php

echo http_build_query(['user_ids' => [1313346,1313342,1313345]]);
// output:
//      user_ids%5B0%5D=1313346&user_ids%5B1%5D=1313342&user_ids%5B2%5D=1313345


Expected result:
----------------
user_ids%5B%5D=1313346&user_ids%5B%5D=1313342&user_ids%5B%5D=1313345

Actual result:
--------------
user_ids%5B0%5D=1313346&user_ids%5B1%5D=1313342&user_ids%5B2%5D=1313345

Patches

Pull Requests

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Apr 02 21:01:29 2025 UTC