Bug #71835 [Ana->Csd]: json_encode sometimes incorrectly detects recursion with JsonSerializable
Edit report at https://bugs.php.net/bug.php?id=71835&edit=1
ID: 71835
Updated by: laruence@php.net
Reported by: icarpenter at leadid dot com
Summary: json_encode sometimes incorrectly detects recursion
with JsonSerializable
-Status: Analyzed
+Status: Closed
Type: Bug
Package: JSON related
PHP Version: 7.0.4
Assigned To: bukka
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of bukka
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7e069daa89f05c1fa4127b2cedfd5586dbfc810e
Log: Fix bug #71835 (json_encode sometimes incorrectly detects recursion with JsonSerializable)
Previous Comments:
------------------------------------------------------------------------
[2016-03-17 20:00:28] bukka@php.net
@laruence yeah that's a tricky one. I will think about it a bit more during this or next
weekend.
------------------------------------------------------------------------
[2016-03-16 13:01:57] laruence@php.net
Hmm, I can not think out of a good fix for this, @bukka, what do you think?
------------------------------------------------------------------------
[2016-03-16 02:59:32] laruence@php.net
hmm, the problem is get_object_vars maybe return directly object->properties, which make it looks
like a recursive array ,
------------------------------------------------------------------------
[2016-03-16 02:00:51] icarpenter at leadid dot com
Description:
------------
If a class that implements JsonSerializable returns an array of get_object_vars($this) in its
jsonSerialize method, and if that class is in an array that is json_encode'd,
JSON_ERROR_RECURSION is returned.
This does not seem to happen if jsonSerialize returns get_object_vars($this) not enclosed an array,
nor does it seem to happen if the object itself is json_encode'd
Test script:
---------------
https://3v4l.org/OoR7D
Expected result:
----------------
string(4) "[[]]"
bool(false)
string(6) "[[[]]]"
bool(false)
string(2) "[]"
bool(false)
string(4) "[[]]"
bool(false)
Actual result:
--------------
string(4) "[[]]"
bool(false)
bool(false)
bool(true)
string(2) "[]"
bool(false)
string(4) "[[]]"
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71835&edit=1
Thread (6 messages)