From:
Operating system: Linux
PHP version: 5.3.6
Package: JSON related
Bug Type: Bug
Bug description:Empty string in json_decode doesn't set/reset json_last_error
Description:
------------
If you decode an empty json value, the internal error state doesn't
change.
Decode a valid json value and after that an empty value, the error state is
0
Decode an invalid json value and after that an empty value, the error state
remains 4 (JSON_ERROR_SYNTAX) (I think it's the same for all error states,
but haven't actually tested)
I'm not quite sure whether an empty string is valid json and should reset
the error state to 0 or whether it is invalid json and should set the error
state to 4. Because a valid empty json string is '""' and not ''
Test script:
---------------
<?php
error_reporting(E_ALL);
json_decode('{"test":"test"}');
var_dump(json_last_error());
json_decode("");
var_dump(json_last_error());
json_decode("invalid json");
var_dump(json_last_error());
json_decode("");
var_dump(json_last_error());
?>
Expected result:
----------------
int(0)
int(0)
int(4)
int(0)
OR
int(0)
int(4)
int(4)
int(4)
Actual result:
--------------
int(0)
int(0)
int(4)
int(4)
--
Edit bug report at http://bugs.php.net/bug.php?id=54484&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=54484&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=54484&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=54484&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=54484&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=54484&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=54484&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=54484&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=54484&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=54484&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=54484&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=54484&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=54484&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=54484&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=54484&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54484&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54484&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=54484&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=54484&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=54484&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=54484&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=54484&r=mysqlcfg