Bug #67585 [Opn]: curl_setopt POSTFIELDS doesn't handle nested arrays as it should
| From: | zelnaga at gmail dot com | Date: | Tue, 29 Jul 2014 01:37:27 +0000 |
| Subject: | Bug #67585 [Opn]: curl_setopt POSTFIELDS doesn't handle nested arrays as it should | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186850@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67585&edit=1
ID: 67585
User updated by: zelnaga at gmail dot com
Reported by: zelnaga at gmail dot com
Summary: curl_setopt POSTFIELDS doesn't handle nested arrays
as it should
Status: Open
Type: Bug
Package: cURL related
Operating System: Windows 7
PHP Version: 5.6.0RC2
Block user comment: N
Private report: N
New Comment:
I accidentally swapped the expected output and the actual output when reporting this bug. FYI.
Previous Comments:
------------------------------------------------------------------------
[2014-07-07 14:49:38] zelnaga at gmail dot com
Description:
------------
<?php
$data = array(
'submit' => 'submit',
'var' => array(1, 2)
);
echo http_build_query($data, '', '&');
?>
That'll output the following:
submit=submit&var%5B0%5D=1&var%5B1%5D=1
It seems like curl_setopt(..., CURLOPT_POSTFIELDS, $data) ought to behave similarly but it
doesn't.
Test script:
---------------
<?php
$data = array(
'submit' => 'submit',
'var' => array(1, 2)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.domain.tld/script.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
echo curl_exec($ch);
Expected result:
----------------
Array
(
[submit] => submit
[var] => Array
)
Actual result:
--------------
Array
(
[submit] => submit
[var] => Array
(
[0] => 1
[1] => 2
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67585&edit=1