3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Recursion implements JsonSerializable { public function __construct() { $this->cnt = 3; } public function jsonSerialize() { if ($this->cnt < 1) { return null; } $this->cnt--; return array($this->cnt => $this); } } var_dump(json_encode(new Recursion()));
based on NZDAB
Output for 5.5.0 - 7.1.0
bool(false)
Output for 5.4.4 - 5.4.45
Warning: json_encode(): recursion detected in /in/7qinr on line 18 string(16) "{"2":{"1":null}}"
Output for 5.4.0 - 5.4.3
string(18) "{"2":{"1":[null]}}"
Output for 5.0.5 - 5.3.29
Fatal error: Interface 'JsonSerializable' not found in /in/7qinr on line 3
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Fatal error: Class 'JsonSerializable' not found in /in/7qinr on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/7qinr on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/7qinr on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/7qinr on line 3
Process exited with code 255.