3 * Simple wrapper for json_econde and json_decode that falls back on Services_JSON class
5 if ( !defined( 'MEDIAWIKI' ) ) {
10 public static function encode( $value, $isHtml = false ) {
11 // Some versions of PHP have a broken json_encode, see PHP bug
12 // 46944. Test encoding an affected character (U+20000) to
14 if ( !function_exists( 'json_encode' ) ||
$isHtml ||
strtolower( json_encode( "\xf0\xa0\x80\x80" ) ) != '\ud840\udc00' ) {
15 $json = new Services_JSON();
16 return $json->encode( $value, $isHtml );
18 return json_encode( $value );
22 public static function decode( $value, $assoc = self
::AS_ARRAY
) {
23 if ( !function_exists( 'json_decode' ) ) {
24 $json = new Services_JSON();
25 $jsonDec = $json->decode( $value );
27 $jsonDec = wfObjectToArray( $jsonDec );
31 return json_decode( $value, $assoc );