public static function encodeJSON($o) { if (!$o) { return null; } $r = array(); if (function_exists('json_encode')) { // PHP 5 >= 5.2.0, PECL json >= 1.2.0 //echo "*Fast JSON encode<br/>"; $r = json_encode($o); } else { // php-coded standard json, very slow //echo "*Slow JSON encode<br/>"; $encodeJson = new Services_JSON(); // object if (!$encodeJson) { return $r; } // get as an associative array, not as object with fields $r = $encodeJson->Encode($o); } return $r; }