Re: json_encode() behavior for incorrectly encoded strings
| From: | Nikita Popov | Date: | Wed, 27 Jun 2012 12:19:15 +0000 |
| Subject: | Re: json_encode() behavior for incorrectly encoded strings | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-60991@lists.php.net to get a copy of this message | ||
On Wed, Jun 27, 2012 at 1:40 PM, Pierre Joye <pierre.php@gmail.com> wrote:
> hi,
>
> On Wed, Jun 27, 2012 at 1:30 PM, Nikita Popov <nikita.ppv@googlemail.com> wrote:
>
>>> Why not in the spirit of others have a new function json_last_error_msg() or
>>> something similar?
>>
>> I implemented it with json_last_error(true) returning just a string,
>> not an array. You can get the array using array(json_last_error(),
>> json_last_error(true)) if you really want. But usually you will only
>> need one of them as they both have different use cases. The
>> stringified version for debugging and the error code version for
>> detecting the error programmatically.
>
> I do not think this signature is consistent with the other error
> functions. I'd to go with the _msg or _string equivalent.
I looked at a few other error functions (of which we by the way we
have *loads*, which is a bad sign) and indeed it seems that they all
use a separate function to get the error message. Most use a
xyz_errno() + xyz_error() pair.
So it seems reasonable to instead provide the functionality via
json_last_error_msg().
Any objections?
Nikita