Piwik\Common::getLastJsonError PHP Метод

getLastJsonError() публичный статический Метод

Returns an empty string in case there was no error.
public static getLastJsonError ( ) : string
Результат string
    public static function getLastJsonError()
    {
        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                return '';
            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';
        }
        return 'Unknown error';
    }

Usage Example

Пример #1
0
 private function loadFile($filename)
 {
     $data = file_get_contents($filename);
     $translations = json_decode($data, true);
     if (is_null($translations) && Common::hasJsonErrorOccurred()) {
         throw new \Exception(sprintf('Not able to load translation file %s: %s', $filename, Common::getLastJsonError()));
     }
     if (!is_array($translations)) {
         return array();
     }
     return $translations;
 }
All Usage Examples Of Piwik\Common::getLastJsonError