Req #80536 [Com]: http_build_query dense numerically indexed arrays without brackets flag?
| From: | antonino dot spampinato86 at gmail dot com | Date: | Thu, 31 Dec 2020 16:37:44 +0000 |
| Subject: | Req #80536 [Com]: http_build_query dense numerically indexed arrays without brackets flag? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231320@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80536&edit=1
ID: 80536
Comment by: antonino dot spampinato86 at gmail dot com
Reported by: divinity76 at gmail dot com
Summary: http_build_query dense numerically indexed arrays
without brackets flag?
Status: Open
Type: Feature/Change Request
Package: URL related
PHP Version: Next Minor Version
Block user comment: N
Private report: N
New Comment:
you can't because to recover php use the super global array $_GET and overwrite the last key.
http://exampla.domain.com/index.php?foo=0&foo=1
$_GET['foo'] // 1 not 0 and 1
use https://3v4l.org/ku2oK
Previous Comments:
------------------------------------------------------------------------
[2020-12-20 16:56:42] divinity76 at gmail dot com
Description:
------------
there are some apis which doesn't support http_build_query()'s array method of
foo[0]=a&foo[1]=b&foo[2]=c, instead specifying arrays like foo=a&foo=b&foo=c ,
one such api is Google's Closure Compiler Rest API, https://developers.google.com/closure/compiler/docs/gettingstarted_api
i recently had to generate a POST request to that api through PHP, i ended up doing
```
"output_info=compiled_code&output_info=warnings&output_info=errors&output_info=statistics&"
. http_build_query(array(
'output_format' => 'json',
'compilation_level' => $compile_level,
'warning_level' => 'verbose',
'js_code' => $js_to_minify
))
```
i had to hack the output_info array data in there, instead of doing it the "proper way" of
```
http_build_query(array(
'output_format' => 'json',
'compilation_level' => $compile_level,
'warning_level' => 'verbose',
'js_code' => $js_to_minify,
'output_info' => array('compiled_code', 'warnings',
'errors', 'statistics')
))
```
it would be nice if http_build_query() could get a flag to treat numerically indexed densely
populated arrays (eg what you get from array_values() or
array("a","b","c") ) without brackets.. (there's probably a
better name for it, idk what)
not sure what the flag name should be though,
PHP_QUERY_DENSE_NUMERICALLY_INDEXED_ARRAYS_WITHOUT_BRACKETS kinda feels too long
Test script:
---------------
<?php
echo http_build_query(
["foo"=>["a","b","c"]],
null,
'&',
PHP_QUERY_DENSE_NUMERICALLY_INDEXED_ARRAYS_WITHOUT_BRACKETS
);
Expected result:
----------------
foo=a&foo=b&foo=c
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80536&edit=1