From: Reedy Date: Sun, 12 Aug 2012 19:31:01 +0000 (+0100) Subject: PHP 5.4 has JSON_PRETTY_PRINT X-Git-Tag: 1.31.0-rc.0~22742 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/journal.php?a=commitdiff_plain;h=28e7830d789446fc30ce43ed283f2a16d6031478;p=lhc%2Fweb%2Fwiklou.git PHP 5.4 has JSON_PRETTY_PRINT Use this conditionally when $isHtml is true, and is also running on PHP > = 5.4. Else return default 0 Change-Id: Ief775720a99d1a305c3f9f4ba7cc04eb96817fb3 --- diff --git a/includes/json/FormatJson.php b/includes/json/FormatJson.php index bbcc1856bd..aa60fbdcc0 100644 --- a/includes/json/FormatJson.php +++ b/includes/json/FormatJson.php @@ -41,11 +41,11 @@ class FormatJson { * @return string */ public static function encode( $value, $isHtml = false ) { - if ( !function_exists( 'json_encode' ) || $isHtml ) { + if ( !function_exists( 'json_encode' ) || ( $isHtml && version_compare( PHP_VERSION, '5.4.0', '<' ) ) ) { $json = new Services_JSON(); return $json->encode( $value, $isHtml ); } else { - return json_encode( $value ); + return json_encode( $value, $isHtml ? JSON_PRETTY_PRINT : 0 ); } }