Edit report at http://bugs.php.net/bug.php?id=54058&edit=1
ID: 54058 Updated by: scott...@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] scott...@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