From:
Operating system: Linux
PHP version: 5.3.5
Package: JSON related
Bug Type: Bug
Bug description:json_last_error() doesn't work properly with arrays/objects
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 bug report at http://bugs.php.net/bug.php?id=54058&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=54058&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=54058&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=54058&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=54058&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=54058&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=54058&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=54058&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=54058&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=54058&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=54058&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=54058&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=54058&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=54058&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=54058&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54058&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54058&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=54058&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=54058&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=54058&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=54058&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=54058&r=mysqlcfg