php.net |  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
Description:
------------
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:
----------------
0

Actual result:
--------------
4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-03 04:21 UTC] laruence@php.net
-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] bwoebi@php.net
-Status: Assigned +Status: Wont fix
 [2015-10-03 11:24 UTC] bwoebi@php.net
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] bukka@php.net
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:

https://github.com/php/php-src/commit/a7b3abe4e6f5e2fdfd8d55b676c9ca6b3f9c8cc8#commitcomment-9576811
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC