<?php
class test implements JsonSerializable {
public $a = 2;
public function JsonSerialize() {
return array('b' => 2, 'test'=>$this);
}
}
var_dump(json_encode(new test()));
var_dump(json_last_error_msg());
Deprecated: Return type of test::JsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/o6p5G on line 5
bool(false)
string(18) "Recursion detected"
Warning: json_encode(): recursion detected in /in/o6p5G on line 10
string(34) "{"b":2,"test":{"b":2,"test":null}}"
Fatal error: Call to undefined function json_last_error_msg() in /in/o6p5G on line 11
Process exited with code 255.