1
0
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:
Michael Dowling 2013-02-24 19:38:40 -08:00
parent 9ed3dcc413
commit bc2a86d1b1
2 changed files with 3 additions and 3 deletions

View File

@ -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;
}
/**

View File

@ -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());
}