3v4l.org

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

preferences:
49.63 ms | 402 KiB | 5 Q