diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 4080ee8fb6..accd57cf3a 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -107,6 +107,9 @@ class JsonResponse extends Response }); try { + // Clear json_last_error() + json_encode(null); + $this->data = json_encode($data, $this->encodingOptions); restore_error_handler(); diff --git a/src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php index f4f3c6c416..48b86038a7 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php @@ -203,8 +203,9 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException PHPUnit_Framework_Error_Warning - * @expectedExceptionMessage This error is expected + * @expectedException Exception + * @expectedExceptionMessage Failed calling Symfony\Component\HttpFoundation\Tests\JsonSerializableObject::jsonSerialize() + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php#114688 */ public function testSetContentJsonSerializeError() {