1--TEST-- 2json_encode() Recursion test with JsonSerializable, __debugInfo and var_export 3--FILE-- 4<?php 5 6class SerializingTest implements JsonSerializable 7{ 8 public $a = 1; 9 10 public function __debugInfo() 11 { 12 return [ 'result' => var_export($this, true) ]; 13 } 14 15 public function jsonSerialize(): mixed 16 { 17 var_dump($this); 18 return $this; 19 } 20} 21 22var_dump(json_encode(new SerializingTest())); 23echo "---------\n"; 24var_dump(new SerializingTest()); 25 26?> 27--EXPECT-- 28object(SerializingTest)#1 (1) { 29 ["result"]=> 30 string(52) "\SerializingTest::__set_state(array( 31 'a' => 1, 32))" 33} 34string(7) "{"a":1}" 35--------- 36object(SerializingTest)#1 (1) { 37 ["result"]=> 38 string(52) "\SerializingTest::__set_state(array( 39 'a' => 1, 40))" 41} 42