From 9769e18dd8b5bbd01283378b554f9296cf0baef0 Mon Sep 17 00:00:00 2001 From: user52 Date: Wed, 28 Aug 2013 08:47:37 -0700 Subject: [PATCH] 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( ), ); --- Curl.class.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Curl.class.php b/Curl.class.php index bea9e52..deb780d 100644 --- a/Curl.class.php +++ b/Curl.class.php @@ -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;