public static function encode($value, $options = 0, $depth = 512)
    {
        // multi-characters supported by default
        $options |= JSON_UNESCAPED_UNICODE;

        $data = version_compare(PHP_VERSION, '5.5.0', '>=')
            ? json_encode($value, $options, $depth)
            : json_encode($value, $options);

        if (JSON_ERROR_NONE !== json_last_error()) {
            return $data;
        }

        return version_compare(PHP_VERSION, '5.4.0', '>=')
            ? $data
            : preg_replace_callback("/\\\\u([0-9a-f]{2})([0-9a-f]{2})/iu", function ($pipe) {
                return iconv(
                    strncasecmp(PHP_OS, 'WIN', 3) ? 'UCS-2BE' : 'UCS-2',
                    'UTF-8',
                    chr(hexdec($pipe[1])) . chr(hexdec($pipe[2]))
                );
            }, $data);
    }