3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Recursion implements JsonSerializable { public function __construct() { $this->cnt = 10; } public function jsonSerialize() { if ($this->cnt < 1) { return null; } $this->cnt--; return array($this->cnt => $this); } } var_dump(json_encode(new Recursion()));

preferences:
68.19 ms | 402 KiB | 5 Q