mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-24 18:13:00 +01:00
Allowing more return types from the Response::json() method. Closes #244
This commit is contained in:
parent
9ed3dcc413
commit
bc2a86d1b1
@ -911,7 +911,7 @@ class Response extends AbstractMessage
|
||||
/**
|
||||
* Parse the JSON response body and return an array
|
||||
*
|
||||
* @return array
|
||||
* @return array|string|int|bool|float
|
||||
* @throws RuntimeException if the response body is not in JSON format
|
||||
*/
|
||||
public function json()
|
||||
@ -921,7 +921,7 @@ class Response extends AbstractMessage
|
||||
throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error());
|
||||
}
|
||||
|
||||
return $data ?: array();
|
||||
return $data === null ? array() : $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -832,7 +832,7 @@ class ResponseTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
{
|
||||
$response = new Response(200, array(), '{"foo": "bar"}');
|
||||
$this->assertEquals(array('foo' => 'bar'), $response->json());
|
||||
// Always return an array from the json method
|
||||
// Return array when null is a service response
|
||||
$response = new Response(200);
|
||||
$this->assertEquals(array(), $response->json());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user