php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53301 http_build_query unexpected behavior
Submitted: 2010-11-12 20:26 UTC Modified: 2010-12-25 20:52 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rbysa at yahoo dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.4 OS: Ubuntu
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: rbysa at yahoo dot com
New email:
PHP Version: OS:

 

 [2010-11-12 20:26 UTC] rbysa at yahoo dot com
Description:
------------
http_build_query truncates large integer keys to 12 digits regardless of them 
being passed as a string, integer, or float. 

However if the integer value is cast to a string and appended with non-integer 
characters the key is not truncated.

Test script:
---------------
$var = 1234567890123
echo http_build_query($var);

$var = (string)1234567890123
echo http_build_query($var);

$var = (float)1234567890123
echo http_build_query($var);

$var = "1234567890123.asd"
echo http_build_query($var);

Expected result:
----------------
Array([0]=>1234567890123)
Array([0]=>1234567890123)
Array([0]=>1234567890123)
Array([0]=>"1234567890123.asd")

Actual result:
--------------
Array([0]=>123456789012)
Array([0]=>123456789012)
Array([0]=>123456789012)
Array([0]=>"1234567890123.asd")

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-12 20:34 UTC] rbysa at yahoo dot com
Also I do want to mention that I saw the previous bug report on this issue

http://bugs.php.net/bug.php?id=49023

However this bug report has been labeled "bogus" even though the documentation 
does not support the mentioned behavior.
 [2010-11-12 22:00 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-11-12 22:00 UTC] felipe@php.net
You need to use:

$var = array('12345678901' => 'foo');
var_dump(http_build_query($var));

As said in the other bug report.
 [2010-11-12 22:38 UTC] rbysa at yahoo dot com
Your example does not represent the problem. In my haste I messed up my own 
example code but here it is again.

$var = "1234567890123";
$varArray = array();
$varArray[$var]= "foo";
$build = http_build_query($varArray);
$result = array();
parse_str($build, $result);
print_r($result);

//Expect Array( "1234567890123"=>"foo")
//Actual Array( "123456789012" =>"foo")
 [2010-11-12 22:41 UTC] felipe@php.net
-Status: Bogus +Status: Open
 [2010-11-12 22:41 UTC] felipe@php.net
I got the expected result...

Array
(
    [1234567890123] => foo
)
 [2010-12-12 18:45 UTC] iliaa@php.net
-Status: Open +Status: Bogus
 [2010-12-12 18:45 UTC] iliaa@php.net
Cannot reproduce the issue either.
 [2010-12-25 20:45 UTC] rbysa at yahoo dot com
PHP Version 5.2.4-2ubuntu5.10

Here is another test case

$test = array('123456789012345=>'9780553', 1=>12312312312);
print_r($test) //This line looks correct
echo http_build_query($test) //This line does not

Here is the output
Array ( [123456789012345] => 9780553 [1] => 12312312312 ) 
123456789012=9780553&1=12312312312
 [2010-12-25 20:52 UTC] rbysa at yahoo dot com
-PHP Version: 5.3.3 +PHP Version: 5.2.4
 [2010-12-25 20:52 UTC] rbysa at yahoo dot com
Incorrect PHP Version
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 27 11:00:03 2025 UTC