: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @param int $code response code of the cURL request
* @param string $raw_body the raw body of the cURL response
* @param string $headers raw header string from cURL response
* @param array $json_args arguments to pass to json_decode function
public function __construct($code, $raw_body, $headers, $json_args = array())
$this->headers = $this->parseHeaders($headers);
$this->raw_body = $raw_body;
// make sure raw_body is the first argument
array_unshift($json_args, $raw_body);
if (function_exists('json_decode')) {
$json = call_user_func_array('json_decode', $json_args);
if (json_last_error() === JSON_ERROR_NONE) {
* if PECL_HTTP is not available use a fall back function
* thanks to ricardovermeltfoort@gmail.com
* http://php.net/manual/en/function.http-parse-headers.php#112986
* @param string $raw_headers raw headers
private function parseHeaders($raw_headers)
if (function_exists('http_parse_headers')) {
return http_parse_headers($raw_headers);
foreach (explode("\n", $raw_headers) as $i => $h) {
$h = explode(':', $h, 2);
if (!isset($headers[$h[0]])) {
$headers[$h[0]] = trim($h[1]);
} elseif (is_array($headers[$h[0]])) {
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1])));
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1])));
if (substr($h[0], 0, 1) == "\t") {
$headers[$key] .= "\r\n\t".trim($h[0]);
$headers[0] = trim($h[0]);