3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class test implements JsonSerializable { public $a = 2; public function JsonSerialize() { return array('test'=>array('c' => $this)); } } var_dump(json_encode(new test(), JSON_PARTIAL_OUTPUT_ON_ERROR)); var_dump(json_last_error_msg());
based on 2k2Bi
Output for 5.5.0 - 7.1.0
string(34) "{"test":{"c":{"test":{"c":null}}}}" string(18) "Recursion detected"
Output for 5.4.0 - 5.4.45
Notice: Use of undefined constant JSON_PARTIAL_OUTPUT_ON_ERROR - assumed 'JSON_PARTIAL_OUTPUT_ON_ERROR' in /in/GbKSd on line 10 Warning: json_encode() expects parameter 2 to be long, string given in /in/GbKSd on line 10 NULL Fatal error: Call to undefined function json_last_error_msg() in /in/GbKSd on line 11
Process exited with code 255.
Output for 5.0.5 - 5.3.29
Fatal error: Interface 'JsonSerializable' not found in /in/GbKSd on line 3
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Fatal error: Class 'JsonSerializable' not found in /in/GbKSd 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/GbKSd 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/GbKSd on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/GbKSd on line 3
Process exited with code 255.