|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70623 json_last_error() for json_decode("") is 4
Submitted: 2015-10-02 15:19 UTC Modified: 2015-10-04 17:09 UTC
From: mikeffrancis at gmail dot com Assigned: bukka (profile)
Status: Wont fix Package: json (PECL)
PHP Version: 7.0.0RC4 OS: Ubuntu 14.04.3 LTS
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-10-02 15:19 UTC] mikeffrancis at gmail dot com
Just testing out PHP7 and decoding an empty string is different for PHP 5.6.* and PHP 7.

Not sure if this is a bug with the current version of PHP or with PHP7 but surely the responses should be the same.

Test script:
json_decode(""); var_dump(json_last_error());

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-03 04:21 UTC]
-Assigned To: +Assigned To: bukka
 [2015-10-03 04:36 UTC] ansouphorn at gmail dot com
In PHP7, if empty string is given, should return 4 which is the PHP_JSON_ERROR_SYNTAX. I think it is not a bug and it works as it supposed to.
 [2015-10-03 11:24 UTC]
-Status: Assigned +Status: Wont fix
 [2015-10-03 11:24 UTC]
This was an intentional change, as said before, nothing is not a valid JSON expression.
 [2015-10-03 12:53 UTC] mikeffrancis at gmail dot com
Ok - surely this is a bug with current versions then if it should return a different value for "" - going forward?
 [2015-10-04 17:09 UTC]
As Bob says, this was an intentional change in PHP 7. It was originally added also to 5.5 5.6 but it was reverted as it would be too big BC for point release.

See commit discussion about that:
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 14:01:27 2020 UTC