Bug #54058 [Opn->Csd]: json_last_error() doesn't work properly with arrays/objects
| From: | scottmac@php.net | Date: | Mon, 21 Feb 2011 08:09:44 +0000 |
| Subject: | Bug #54058 [Opn->Csd]: json_last_error() doesn't work properly with arrays/objects | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-158922@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54058&edit=1
ID: 54058
Updated by: scottmac@php.net
Reported by: slusarz at curecanti dot org
Summary: json_last_error() doesn't work properly with
arrays/objects
-Status: Open
+Status: Closed
Type: Bug
Package: JSON related
Operating System: Linux
PHP Version: 5.3.5
-Assigned To:
+Assigned To: scottmac
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2011-02-21 09:09:04] scottmac@php.net
Automatic comment from SVN on behalf of scottmac
Revision: http://svn.php.net/viewvc/?view=revision&revision=308529
Log: Fix Bug #54058, invalid utf-8 doesn't set json_encode() in all
cases
------------------------------------------------------------------------
[2011-02-21 07:05:47] slusarz at curecanti dot org
Description:
------------
json_last_error() doesn't work properly in arrays/objects. If an error
occurs when encoding a property/key, and it isn't the LAST property/key,
json_last_error() is reset to 0.
json_last_error() should report the last parsing error from the last
json_encode() call AS AN ENTIRETY, not the last internal encoding step
that takes place inside the function.
Test script:
---------------
$bad_utf8 = quoted_printable_decode('=B0');
json_encode($bad_utf8);
print "ERROR: " . json_last_error() . "\n";
$a = new stdclass;
$a->foo = quoted_printable_decode('=B0');
json_encode($a);
print "ERROR: " . json_last_error() . "\n";
$b = new stdclass;
$b->foo = $bad_utf8;
$b->bar = 1;
json_encode($b);
print "ERROR: " . json_last_error() . "\n";
$c = array(
'foo' => $bad_utf8,
'bar' => 1
);
json_encode($c);
print "ERROR: " . json_last_error() . "\n";
Expected result:
----------------
ERROR: 5
ERROR: 5
ERROR: 5
ERROR: 5
Actual result:
--------------
ERROR: 5
ERROR: 5
ERROR: 0
ERROR: 0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54058&edit=1