Bug #54484 [Asn->Csd]: Empty string in json_decode doesn't set/reset json_last_error
| From: | iliaa@php.net | Date: | Wed, 01 Jun 2011 09:44:51 +0000 |
| Subject: | Bug #54484 [Asn->Csd]: Empty string in json_decode doesn't set/reset json_last_error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161084@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54484&edit=1
ID: 54484
Updated by: iliaa@php.net
Reported by: wildcat at the-wildcat dot de
Summary: Empty string in json_decode doesn't set/reset
json_last_error
-Status: Assigned
+Status: Closed
Type: Bug
Package: JSON related
Operating System: Linux
PHP Version: 5.3.6
-Assigned To: scottmac
+Assigned To: iliaa
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-06-01 11:44:40] iliaa@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=311708
Log: Fixed bug #54484 (Empty string in json_decode doesn't reset
json_last_error()).
------------------------------------------------------------------------
[2011-04-08 08:20:41] scottmac@php.net
a string of length 0 skips the decoder and returns null. I'm thinking it
should
set the error code to 4 so I'll fix it to do so.
------------------------------------------------------------------------
[2011-04-07 14:24:55] wildcat at the-wildcat dot de
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 this bug report at http://bugs.php.net/bug.php?id=54484&edit=1