Req #60584 [Com]: headers_list() should return in a `$key => $value` fashion
| From: | anon at anon dot anon | Date: | Thu, 22 Dec 2011 02:27:03 +0000 |
| Subject: | Req #60584 [Com]: headers_list() should return in a `$key => $value` fashion | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-166036@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60584&edit=1
ID: 60584
Comment by: anon at anon dot anon
Reported by: toms at mindboiler dot lv
Summary: headers_list() should return in a
$key => $value
fashion
Status: Wont fix
Type: Feature/Change Request
Package: Network related
Operating System: CentOS 2.6.18-274.12.1.el5xen
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
This could not work. Each sent cookie in an HTTP response has its own Set-Cookie header, and there
is no syntax accepted by browsers for combining them into one (separators like commas or semi-colons
already have other meanings in the Set-Cookie syntax). Blame Netscape for coming up with that, but
17 years later there's nothing that can be done about it.
Example:
setcookie('foo', 'bar');
setcookie('abc', '123');
var_dump(headers_list());
Output:
array(2) {
[0]=>
string(19) "Set-Cookie: foo=bar"
[1]=>
string(19) "Set-Cookie: abc=123"
}
See also: http://curl.haxx.se/rfc/cookie_spec.html
Previous Comments:
------------------------------------------------------------------------
[2011-12-21 15:56:36] cataphract@php.net
While I don't think HTTP allows repeated headers, they're common in the wild, so key =>
value is not an option (maybe if the value was an array, but in any case both options break
backwards compatibility).
Thank you for the suggestion, anyway.
------------------------------------------------------------------------
[2011-12-21 12:37:53] toms at mindboiler dot lv
Changed the summary a little, OS version.
------------------------------------------------------------------------
[2011-12-21 12:34:34] toms at mindboiler dot lv
Description:
------------
The function headers_list() returns the headers in a numeric array fashion,
although, headers are, AFAIK, always in a Key: Value fashion, therefore,
associative array would be a better choice.
More on this, header_remove() works by simply passing the key, therefore, in
background, headers have their key representation, I suppose.
I've made an example function that uses this function, for a header lookup, but
ends up in "lots of lines" compared to what could be replaced with one:
https://gist.github.com/1505803
P.S. This is my first file in PHP Bugs section, please guide me if I have given
not enough information.
Test script:
---------------
header('Test-Header: A random result');
var_dump(headers_list());
Expected result:
----------------
array(5) {
["X-Powered-By"]=>
string(23) "PHP/5.3.3"
["Expires"]=>
string(38) "Thu, 19 Nov 1981 08:52:00 GMT"
["Cache-Control"]=>
string(77) "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
["Pragma"]=>
string(16) "no-cache"
["Test-Header"]=>
string(28) "A random result"
}
Actual result:
--------------
array(5) {
[0]=>
string(23) "X-Powered-By: PHP/5.3.3"
[1]=>
string(38) "Expires: Thu, 19 Nov 1981 08:52:00 GMT"
[2]=>
string(77) "Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0"
[3]=>
string(16) "Pragma: no-cache"
[4]=>
string(28) "Test-Header: A random result"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60584&edit=1