Bug #69187 [Asn]: json_last_error return BC in PHP7

From: Date: Thu, 05 Mar 2015 19:23:14 +0000
Subject: Bug #69187 [Asn]: json_last_error return BC in PHP7
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191198@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69187&edit=1

 ID:                 69187
 Updated by:         aharvey@php.net
 Reported by:        hdtfonseca at gmail dot com
 Summary:            json_last_error return BC in PHP7
 Status:             Assigned
 Type:               Bug
 Package:            JSON related
 Operating System:   linux
 PHP Version:        master-Git-2015-03-04 (Git)
 Assigned To:        bukka
 Block user comment: N
 Private report:     N

 New Comment:

Well, that was embarrassing. :)

Thanks for looking into this and in advance for the patch!


Previous Comments:
------------------------------------------------------------------------
[2015-03-05 18:23:46] bukka@php.net

Hi Adam, this is actually caused by your commit ( https://github.com/php/php-src/commit/a7b3abe4e6f5e2fdfd8d55b676c9ca6b3f9c8cc8
) :). The reason is the null is converted to empty string... The same will be for false.

I think that it makes sense to not emit error for null or false but only for empty string.
json_decode already returns number when you pass number (json_decode(1)) so it makes sense to have
it consistent. There is still a small inconsistency with boolean - json_decode(false) returns NULL
and json_decode(true) returns 1. However I'm not sure if it's worthy it to break BC (even
slightly)...

I will apply the patch for NULL and FALSE in a couple days if no objections.

------------------------------------------------------------------------
[2015-03-04 19:36:46] aharvey@php.net

Jakub, is this expected, and if so, can you update UPGRADING with the situations where this will
happen, please?

------------------------------------------------------------------------
[2015-03-04 18:13:44] hdtfonseca at gmail dot com

Description:
------------
The output of the function json_last_error() is different in PHP master in some situations and this
is causing a BC break.



Test script:
---------------
json_decode(null, true); 
echo json_last_error();

Expected result:
----------------
0

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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69187&edit=1


Thread (13 messages)

« previous php.bugs (#191198) next »