From 414ba16d8aa971f5fe42126986666199526ecfb7 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 6 Oct 2017 12:42:34 +0200 Subject: [PATCH] Util/Json: Make encode compatible to PHP < 5.5 --- library/Icinga/Util/Json.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Util/Json.php b/library/Icinga/Util/Json.php index 3bd988bc0..0f757c745 100644 --- a/library/Icinga/Util/Json.php +++ b/library/Icinga/Util/Json.php @@ -23,7 +23,13 @@ class Json */ public static function encode($value, $options = 0, $depth = 512) { - $encoded = json_encode($value, $options, $depth); + if (version_compare(phpversion(), '5.4.0', '<')) { + $encoded = json_encode($value); + } else if (version_compare(phpversion(), '5.5.0', '<')) { + $encoded = json_encode($value, $options); + } else { + $encoded = json_encode($value, $options, $depth); + } if (json_last_error() !== JSON_ERROR_NONE) { throw new JsonEncodeException('%s: %s', static::lastErrorMsg(), var_export($value, true)); }