Change of $depth behaviour in json_encode() on PHP 8.1

php.internals

Benjamin Morel

4 years ago
Hi internals, I noticed a change of behaviour on PHP 8.1: https://3v4l.org/DoG4A ``` // 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)); ``` On PHP 8.1, all three examples successfully encode the input object, while on PHP <= 8.0, json_encode() returns false as this exceeds the max depth. I couldn't find a note about this in the migration guide for PHP 8.1. Is this documented, or is this a regression that should be fixed? Thanks in advance, — Benjamin

Kamil Tekiela

4 years ago
Hi Benjamin, This is a bug. Please report it on https://bugs.php.net/ See https://3v4l.org/vFgh0 https://github.com/php/php-src/commit/f9f8c1c79cac1b03279190e0c5513a51881615f9 https://github.com/php/php-src/pull/6811 Best Regards, Kamil

Benjamin Morel

4 years ago
> > > This is a bug. Please report it on https://bugs.php.net/ > > See https://3v4l.org/vFgh0 > > https://github.com/php/php-src/commit/f9f8c1c79cac1b03279190e0c5513a51881615f9 > https://github.com/php/php-src/pull/6811 > > Best Regards, > Kamil >
Thank you! Reported as https://bugs.php.net/bug.php?id=81532