Skip to content

Instantly share code, notes, and snippets.

@phenix-factory
Created October 16, 2014 10:03
Show Gist options
  • Save phenix-factory/c7381c9f668d72be1efd to your computer and use it in GitHub Desktop.
Save phenix-factory/c7381c9f668d72be1efd to your computer and use it in GitHub Desktop.
SPIP: Log pour les erreurs d'encodage/décodage JSON
<?php
/**
* Fonction qui écrit dans les log de SPIP les erreurs d'encodage/décodage JSON
*
* @param string $filename Nom du fichier de log SPIP à utiliser
* @access public
*/
function spip_log_erreur_json($filename='json_erreur') {
// Gestion des erreur JSON
switch (json_last_error()) {
case JSON_ERROR_NONE:
spip_log('No errors', $filename);
break;
case JSON_ERROR_DEPTH:
spip_log('Maximum stack depth exceeded', $filename);
break;
case JSON_ERROR_STATE_MISMATCH:
spip_log('Underflow or the modes mismatch', $filename);
break;
case JSON_ERROR_CTRL_CHAR:
spip_log('Unexpected control character found', $filename);
break;
case JSON_ERROR_SYNTAX:
spip_log('Syntax error, malformed JSON', $filename);
break;
case JSON_ERROR_UTF8:
spip_log('Malformed UTF-8 characters, possibly incorrectly encoded', $filename);
break;
default:
spip_log('Unknown error', $filename);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment