Bug #67585 [NEW]: curl_setopt POSTFIELDS doesn't handle nested arrays as it should

From: Date: Mon, 07 Jul 2014 14:49:38 +0000
Subject: Bug #67585 [NEW]: curl_setopt POSTFIELDS doesn't handle nested arrays as it should
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186502@lists.php.net to get a copy of this message
From:             zelnaga at gmail dot com
Operating system: Windows 7
PHP version:      5.6.0RC2
Package:          cURL related
Bug Type:         Bug
Bug description:curl_setopt POSTFIELDS doesn't handle nested arrays as it should

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 bug report at https://bugs.php.net/bug.php?id=67585&edit=1
-- 



Thread (4 messages)

« previous php.bugs (#186502) next »