note 119985 added to function.json-last-error
| From: | davi dot marcondes dot moreira at gmail dot com | Date: | Tue, 04 Oct 2016 18:17:28 +0000 |
| Subject: | note 119985 added to function.json-last-error | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206772@lists.php.net to get a copy of this message | ||
In any case, I've made another approach for the example on this page:
```
<?php
namespace \Json
class Helper
{
/**
* @var array
*/
protected $errorReference = [
JSON_ERROR_NONE => 'No error has occurred.',
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly
encoded.',
JSON_ERROR_SYNTAX => 'Syntax error.',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
// These last 3 messages are only supported on PHP >= 5.5.
// See http://php.net/json_last_error#refsect1-function.json-last-error-returnvalues
JSON_ERROR_RECURSION => 'One or more recursive references in the value to be
encoded.',
JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be
encoded.',
JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was
given.',
];
/**
* @var string
*/
const JSON_UNKNOWN_ERROR = 'Unknown error.';
/**
* Provides the error message, related to json_last_error().
*
* If the error code is not found, returns a default
Unknown error message.
*
* @param int $errorCode Return from json_last_error()
*
* @return string The error message.
*/
public static function getLastErrorMessage($errorCode)
{
if (!array_key_exists($errorCode, $this->errorReference)) {
return self::JSON_UNKNOWN_ERROR;
}
return $this->errorReference[$errorCode];
}
}
```
----
Server IP: 72.52.91.14
Probable Submitter: 189.47.146.30
----
Manual Page -- http://php.net/manual/en/function.json-last-error.php
Edit -- https://master.php.net/note/edit/119985
Del: integrated -- https://master.php.net/note/delete/119985/integrated
Del: useless -- https://master.php.net/note/delete/119985/useless
Del: bad code -- https://master.php.net/note/delete/119985/bad+code
Del: spam -- https://master.php.net/note/delete/119985/spam
Del: non-english -- https://master.php.net/note/delete/119985/non-english
Del: in docs -- https://master.php.net/note/delete/119985/in+docs
Del: other reasons-- https://master.php.net/note/delete/119985
Reject -- https://master.php.net/note/reject/119985
Search -- https://master.php.net/manage/user-notes.php