From 08e3be88064e06d30a171d98aaae82f5928eec8d Mon Sep 17 00:00:00 2001 From: sam marshall Date: Tue, 20 Sep 2016 14:49:10 +0100 Subject: [PATCH] MDL-56038 Web services: json_last_error_msg not in PHP 5.4 --- lib/ajax/service.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ajax/service.php b/lib/ajax/service.php index 5437f1a4b5d..43ce3f70438 100644 --- a/lib/ajax/service.php +++ b/lib/ajax/service.php @@ -36,7 +36,12 @@ $rawjson = file_get_contents('php://input'); $requests = json_decode($rawjson, true); if ($requests === null) { - $lasterror = json_last_error_msg(); + if (function_exists('json_last_error_msg')) { + $lasterror = json_last_error_msg(); + } else { + // Fall back to numeric error for older PHP version. + $lasterror = json_last_error(); + } throw new coding_exception('Invalid json in request: ' . $lasterror); } $responses = array();