Overview

Namespaces

  • Webmozart
    • Json

Classes

  • Webmozart\Json\JsonDecoder
  • Webmozart\Json\JsonEncoder
  • Webmozart\Json\JsonError
  • Webmozart\Json\JsonValidator

Exceptions

  • Webmozart\Json\DecodingFailedException
  • Webmozart\Json\EncodingFailedException
  • Webmozart\Json\FileNotFoundException
  • Webmozart\Json\InvalidSchemaException
  • Webmozart\Json\ValidationFailedException
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 
<?php

/*
 * This file is part of the Webmozart JSON package.
 *
 * (c) Bernhard Schussek <bschussek@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Webmozart\Json;

/**
 * @since  1.0
 *
 * @author Bernhard Schussek <bschussek@gmail.com>
 */
class JsonError
{
    /**
     * User-land implementation of `json_last_error_msg()` for PHP < 5.5.
     *
     * @return string The last JSON error message.
     */
    public static function getLastErrorMessage()
    {
        return self::getErrorMessage(json_last_error());
    }

    /**
     * Returns the error message of a JSON error code.
     *
     * @param int $error The error code.
     *
     * @return string The error message.
     */
    public static function getErrorMessage($error)
    {
        switch ($error) {
            case JSON_ERROR_NONE:
                return 'JSON_ERROR_NONE';
            case JSON_ERROR_DEPTH:
                return 'JSON_ERROR_DEPTH';
            case JSON_ERROR_STATE_MISMATCH:
                return 'JSON_ERROR_STATE_MISMATCH';
            case JSON_ERROR_CTRL_CHAR:
                return 'JSON_ERROR_CTRL_CHAR';
            case JSON_ERROR_SYNTAX:
                return 'JSON_ERROR_SYNTAX';
            case JSON_ERROR_UTF8:
                return 'JSON_ERROR_UTF8';
        }

        if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
            switch ($error) {
                case JSON_ERROR_RECURSION:
                    return 'JSON_ERROR_RECURSION';
                case JSON_ERROR_INF_OR_NAN:
                    return 'JSON_ERROR_INF_OR_NAN';
                case JSON_ERROR_UNSUPPORTED_TYPE:
                    return 'JSON_ERROR_UNSUPPORTED_TYPE';
            }
        }

        return 'JSON_ERROR_UNKNOWN';
    }

    private function __construct()
    {
    }
}
Webmozart JSON API API documentation generated by ApiGen