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:7
Avg. Score:3.9 ± 1.4
Reproduced:6 of 6 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (16.7%)
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 18:01:24 2019 UTC