Fix "Notice: Array to string conversion"

Fix "Notice: Array to string conversion" when $value in curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array that contains an empty array. Example that causes Notice:

$data = array(
    'foo' => 'bar',
    'baz' => array(
    ),
);
This commit is contained in:
user52
2013-08-28 08:47:37 -07:00
parent 29e39ced39
commit 9769e18dd8
+15 -3
View File
@@ -97,10 +97,22 @@ class Curl {
}
function _postfields($data) {
$multidimensional = !(count($data) === count($data, COUNT_RECURSIVE));
if (is_array($data)) {
$multidimensional = !(count($data) === count($data, COUNT_RECURSIVE));
if ($multidimensional) {
$data = $this->http_build_multi_query($data);
if ($multidimensional) {
$data = $this->http_build_multi_query($data);
}
else {
// Fix "Notice: Array to string conversion" when $value in
// curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array
// that contains an empty array.
foreach ($data as &$value) {
if (is_array($value) && empty($value)) {
$value = '';
}
}
}
}
return $data;