code = (int) $response->get_error_code(); $this->body = (string) $response->get_error_message(); } else { // cast response to array $response = (array) $response; // look for an HTTP code if (isset($response['response']['code'])) { $this->code = (int) $response['response']['code']; } // look for the response body if (isset($response['body'])) { $this->body = (string) $response['body']; } else { // otherwise use a stringified version of the whole response $this->body = print_r($response, true); } // look for the response headers if (isset($response['headers'])) { // check if we have an array or a traversable object if (is_array($response['headers']) || (is_object($response['headers']) && $response['headers'] instanceof Traversable)) { // iterate all the headers keys and copy them within the internal property foreach ($response['headers'] as $k => $v) { $this->headers[$k] = $v; } } } } } }