|  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...
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 27 21:03:35 2022 UTC