You are here

public static function JsonEncoder::getLastErrorMessage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/serializer/Encoder/JsonEncoder.php \Symfony\Component\Serializer\Encoder\JsonEncoder::getLastErrorMessage()

Resolves json_last_error message.

Return value

string

2 calls to JsonEncoder::getLastErrorMessage()
JsonDecode::decode in vendor/symfony/serializer/Encoder/JsonDecode.php
Decodes data.
JsonEncode::encode in vendor/symfony/serializer/Encoder/JsonEncode.php
Encodes PHP data to a JSON string.

File

vendor/symfony/serializer/Encoder/JsonEncoder.php, line 104

Class

JsonEncoder
Encodes JSON data.

Namespace

Symfony\Component\Serializer\Encoder

Code

public static function getLastErrorMessage() {
  if (function_exists('json_last_error_msg')) {
    return json_last_error_msg();
  }
  switch (json_last_error()) {
    case JSON_ERROR_DEPTH:
      return 'Maximum stack depth exceeded';
    case JSON_ERROR_STATE_MISMATCH:
      return 'Underflow or the modes mismatch';
    case JSON_ERROR_CTRL_CHAR:
      return 'Unexpected control character found';
    case JSON_ERROR_SYNTAX:
      return 'Syntax error, malformed JSON';
    case JSON_ERROR_UTF8:
      return 'Malformed UTF-8 characters, possibly incorrectly encoded';
    default:
      return 'Unknown error';
  }
}