Bug #50407 [Com]: http_build_query() on empty array
| From: | alestork78 at yahoo dot it | Date: | Thu, 21 Jul 2022 13:54:11 +0000 |
| Subject: | Bug #50407 [Com]: http_build_query() on empty array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-241973@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=50407&edit=1
ID: 50407
Comment by: alestork78 at yahoo dot it
Reported by: php at gimme dot org
Summary: http_build_query() on empty array
Status: Not a bug
Type: Bug
Package: URL related
Operating System: Win
PHP Version: 5.2.11
Block user comment: N
Private report: N
New Comment:
In 2022 this in still marked as NOT A BUG because someone did not understand the difference between
"not set" and "empty"?
example.com?foo=bar (set value)
example.com?foo= (set value to "empty")
example.com? (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?
Previous Comments:
------------------------------------------------------------------------
[2012-08-29 14:45:03] 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...
------------------------------------------------------------------------
[2012-02-17 21:23:57] ast dot derek at gmail dot com
Not set is not the same as empty:
http://example.com/?foo=&bar=2&hash=XXXX
$hash = $_GET['hash'];
unset($_GET['hash']);
if ($hash != hash(http_build_query($_GET))) {
echo 'Hash mismatch';
die;
}
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.
------------------------------------------------------------------------
[2010-10-06 13:42:29] adam dot zivner at gmail dot com
Applications often make distinction between empty and not set.
Example:
Set filter to '': http://example.com/articles/?filter=
Don't change filter, get it from cookies: http://example.com/articles/
But of course, this could be wrong way of using this. Is suggested explanation
part of some standard/specification?
------------------------------------------------------------------------
[2009-12-08 10:05:03] jani@php.net
Not setting is same as setting it empty. No bug.
------------------------------------------------------------------------
[2009-12-08 08:31:10] php at gimme dot org
Description:
------------
http_build_query() ignore the
key in array( key => array() )..
Reproduce code:
---------------
<?php
$param = array(
'_COOKIE' => array(),
'_HEADER' => array(
'User-Agent' => 'Mozilla...' ,
),
);
echo http_build_query( $param );
?>
Expected result:
----------------
_COOKIE%5B0%D=&_HEADER%5BUser-Agent%5D=Mozilla...
Actual result:
--------------
_HEADER%5BUser-Agent%5D=Mozilla...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=50407&edit=1