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:8
Avg. Score:3.8 ± 1.3
Reproduced:7 of 7 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (28.6%)
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC