Bug #81532 [Com]: Change of $depth behaviour in json_encode() on PHP 8.1

From: Date: Mon, 18 Oct 2021 06:48:49 +0000
Subject: Bug #81532 [Com]: Change of $depth behaviour in json_encode() on PHP 8.1
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237249@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81532&edit=1 ID: 81532 Comment by: benjamin dot morel at gmail dot com Reported by: benjamin dot morel at gmail dot com Summary: Change of $depth behaviour in json_encode() on PHP 8.1 Status: Open Type: Bug Package: JSON related Operating System: Linux PHP Version: 8.1.0RC4 Block user comment: N Private report: N New Comment: Sorry, I mixed the expected and actual. The expected result is false. Previous Comments: ------------------------------------------------------------------------ [2021-10-17 12:43:55] benjamin dot morel at gmail dot com Description: ------------ The behaviour of the $depth parameter of json_encode() has changed when encoding objects. On PHP 8.1, all three examples below successfully encode the input object, while on PHP <= 8.0, json_encode() returns false as this exceeds the max depth. Discussion: https://externals.io/message/116279 Demo: https://3v4l.org/DoG4A If we replace the $a object with an empty array [], it works: https://3v4l.org/vFgh0 Test script: --------------- // depth 1 $a = new \stdClass(); // depth 2 $b = new \stdClass(); $b->x = $a; // depth 3 $c = new \stdClass(); $c->x = [$a]; var_export(json_encode($a, 0, 0)); echo "\n"; var_export(json_encode($b, 0, 1)); echo "\n"; var_export(json_encode($c, 0, 2)); Expected result: ---------------- '{}' '{"x":{}}' '{"x":[{}]}' Actual result: -------------- false false false ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81532&edit=1

« previous php.bugs (#237249) next »