/** * Encode a PHP object into a JSON string. * * @param object|array $input A PHP object or array * * @return string JSON representation of the PHP object or array * @throws DomainException Provided object could not be encoded to valid JSON */ public static function jsonEncode($input) { $json = json_encode($input); if (function_exists('json_last_error') && ($errno = json_last_error())) { JWT::_handleJsonError($errno); } else { if ($json === 'null' && $input !== null) { throw new DomainException('Null result with non-null input'); } } return $json; }