Merge pull request #2995 from Icinga/bugfix/json-encode-params

Util/Json: Make encode compatible to PHP < 5.5
This commit is contained in:
lippserd 2017-10-06 12:43:44 +02:00 committed by GitHub
commit 9398e5d82a
1 changed files with 7 additions and 1 deletions

View File

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