Helper method to create a JSON error.
private static handleJsonError ( integer $errno ) : void | ||
$errno | integer | An error number from json_last_error() |
return | void |
/** * 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); } elseif ($json === 'null' && $input !== null) { throw new DomainException('Null result with non-null input'); } return $json; }
/** * 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); } elseif ($json === 'null' && $input !== null) { return null; } return $json; }