Bug #71835 [NEW]: json_encode sometimes incorrectly detects recursion with JsonSerializable
From: icarpenter at leadid dot com
Operating system:
PHP version: 7.0.4
Package: JSON related
Bug Type: Bug
Bug description:json_encode sometimes incorrectly detects recursion with JsonSerializable
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 bug report at https://bugs.php.net/bug.php?id=71835&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71835&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71835&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71835&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71835&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71835&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71835&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71835&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71835&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71835&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71835&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71835&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71835&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71835&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71835&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71835&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71835&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71835&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71835&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71835&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71835&r=mysqlcfg
Thread (6 messages)
- icarpenter at leadid dot com