|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50407 http_build_query() on empty array
Submitted: 2009-12-08 08:31 UTC Modified: 2009-12-08 10:05 UTC
From: php at gimme dot org Assigned:
Status: Not a bug Package: URL related
PHP Version: 5.2.11 OS: Win
Private report: No CVE-ID: None
 [2009-12-08 08:31 UTC] php at gimme dot org
http_build_query() ignore the `key` in array( `key` => array() )..

Reproduce code:

$param = array(
	'_COOKIE' => array(),
	'_HEADER' => array(
		'User-Agent' => 'Mozilla...' ,

echo http_build_query( $param );


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-08 10:05 UTC]
Not setting is same as setting it empty. No bug.
 [2010-10-06 13:42 UTC] adam dot zivner at gmail dot com
Applications often make distinction between empty and not set.


Set filter to '':
Don't change filter, get it from cookies:

But of course, this could be wrong way of using this. Is suggested explanation 
part of some standard/specification?
 [2012-02-17 21:23 UTC] ast dot derek at gmail dot com
Not set is not the same as empty:

$hash = $_GET['hash'];

if ($hash != hash(http_build_query($_GET))) {
    echo 'Hash mismatch';

Now we can't check the hash as http_build_query() won't return the

"URL-encoded query string from the associative (or indexed) array provided."

The original array is not used, a filtered copy was
processed instead.
 [2012-08-29 14:45 UTC] arnaud dot morin at gmail dot com
This is, IMHO, a poor design solution because we sometime want to provide a clear value to a parameter... as said before, empty is not the same as not provided...
 [2022-07-21 13:54 UTC] alestork78 at yahoo dot it
In 2022 this in still marked as NOT A BUG because someone did not understand the difference between "not set" and "empty"? (set value)    (set value to "empty")        (do nothing)

The only solution to have things work like above is to rework this bad designed core php function every time? Won't be ever fixed?
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 11:01:30 2024 UTC