3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements JsonSerializable { private $x = 100; public function __toString() { return json_encode($this); } public function jsonSerialize() { return [ "x" => $this->x, ]; } } $t = new Test(); echo $t->__toString();
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
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/InSX1 on line 11 {"x":100}
Output for 8.0.1 - 8.0.30
{"x":100}

preferences:
95.7 ms | 401 KiB | 90 Q