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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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 13:01:29 2024 UTC