From f13956d94b5232b11dadd2ea06add9cfce14a13e Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 18 Mar 2016 21:11:54 +0900 Subject: [PATCH] Fix JSON serialization error on PHP 7 Closes #685. Thanks to @sijad. --- framework/core/src/Api/JsonApiResponse.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/core/src/Api/JsonApiResponse.php b/framework/core/src/Api/JsonApiResponse.php index 80cb4151d..0c79b4dcb 100644 --- a/framework/core/src/Api/JsonApiResponse.php +++ b/framework/core/src/Api/JsonApiResponse.php @@ -22,6 +22,9 @@ class JsonApiResponse extends JsonResponse { $headers['content-type'] = 'application/vnd.api+json'; - parent::__construct($document, $status, $headers, $encodingOptions); + // The call to jsonSerialize prevents rare issues with json_encode() failing with a + // syntax error even though Document implements the JsonSerializable interface. + // See https://github.com/flarum/core/issues/685 + parent::__construct($document->jsonSerialize(), $status, $headers, $encodingOptions); } }