Bug #71835 [Opn]: json_encode sometimes incorrectly detects recursion with JsonSerializable
| From: | laruence@php.net | Date: | Wed, 16 Mar 2016 02:59:32 +0000 |
| Subject: | Bug #71835 [Opn]: json_encode sometimes incorrectly detects recursion with JsonSerializable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199856@lists.php.net to get a copy of this message | ||
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: Open
Type: Bug
Package: JSON related
PHP Version: 7.0.4
Block user comment: N
Private report: N
New Comment:
hmm, the problem is get_object_vars maybe return directly object->properties, which make it looks
like a recursive array ,
Previous Comments:
------------------------------------------------------------------------
[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