1--TEST-- 2Bug #71835 (json_encode sometimes incorrectly detects recursion with JsonSerializable) 3--FILE-- 4<?php 5class SomeClass implements JsonSerializable { 6 public function jsonSerialize(): mixed { 7 return [get_object_vars($this)]; 8 } 9} 10$class = new SomeClass; 11$arr = [$class]; 12var_dump(json_encode($arr)); 13 14class SomeClass2 implements JsonSerializable { 15 public function jsonSerialize(): mixed { 16 return [(array)$this]; 17 } 18} 19$class = new SomeClass2; 20$arr = [$class]; 21var_dump(json_encode($arr)); 22?> 23--EXPECT-- 24string(6) "[[[]]]" 25string(6) "[[[]]]" 26