3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Person { public $name; public $age; public $role; } class Role { public $name; } $person = new Person(); $person->name = 'Name'; $person->age = 20; $person->role = new Role(); $jsonObj = json_encode($person, 0, 1); var_dump($jsonObj); $errors = array( JSON_ERROR_NONE => "JSON_ERROR_NONE", JSON_ERROR_DEPTH => "JSON_ERROR_DEPTH", JSON_ERROR_STATE_MISMATCH => "JSON_ERROR_STATE_MISMATCH", JSON_ERROR_CTRL_CHAR => "JSON_ERROR_CTRL_CHAR", JSON_ERROR_SYNTAX => "JSON_ERROR_SYNTAX", JSON_ERROR_UTF8 => "JSON_ERROR_UTF8", JSON_ERROR_RECURSION => "JSON_ERROR_RECURSION", JSON_ERROR_INF_OR_NAN => "JSON_ERROR_INF_OR_NAN", JSON_ERROR_UNSUPPORTED_TYPE => "JSON_ERROR_UNSUPPORTED_TYPE" ); var_dump($errors[json_last_error()]);
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/AHvH6 on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/AHvH6 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/AHvH6 on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/AHvH6 on line 19
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
bool(false) string(16) "JSON_ERROR_DEPTH"
Output for 5.3.3 - 5.3.29, 5.4.0 - 5.4.45
Warning: json_encode() expects at most 2 parameters, 3 given in /in/AHvH6 on line 19 NULL Notice: Use of undefined constant JSON_ERROR_RECURSION - assumed 'JSON_ERROR_RECURSION' in /in/AHvH6 on line 30 Notice: Use of undefined constant JSON_ERROR_INF_OR_NAN - assumed 'JSON_ERROR_INF_OR_NAN' in /in/AHvH6 on line 31 Notice: Use of undefined constant JSON_ERROR_UNSUPPORTED_TYPE - assumed 'JSON_ERROR_UNSUPPORTED_TYPE' in /in/AHvH6 on line 32 string(15) "JSON_ERROR_NONE"
Output for 5.2.0 - 5.2.17
Warning: json_encode() expects exactly 1 parameter, 3 given in /in/AHvH6 on line 19 NULL Notice: Use of undefined constant JSON_ERROR_NONE - assumed 'JSON_ERROR_NONE' in /in/AHvH6 on line 24 Notice: Use of undefined constant JSON_ERROR_DEPTH - assumed 'JSON_ERROR_DEPTH' in /in/AHvH6 on line 25 Notice: Use of undefined constant JSON_ERROR_STATE_MISMATCH - assumed 'JSON_ERROR_STATE_MISMATCH' in /in/AHvH6 on line 26 Notice: Use of undefined constant JSON_ERROR_CTRL_CHAR - assumed 'JSON_ERROR_CTRL_CHAR' in /in/AHvH6 on line 27 Notice: Use of undefined constant JSON_ERROR_SYNTAX - assumed 'JSON_ERROR_SYNTAX' in /in/AHvH6 on line 28 Notice: Use of undefined constant JSON_ERROR_UTF8 - assumed 'JSON_ERROR_UTF8' in /in/AHvH6 on line 29 Notice: Use of undefined constant JSON_ERROR_RECURSION - assumed 'JSON_ERROR_RECURSION' in /in/AHvH6 on line 30 Notice: Use of undefined constant JSON_ERROR_INF_OR_NAN - assumed 'JSON_ERROR_INF_OR_NAN' in /in/AHvH6 on line 31 Notice: Use of undefined constant JSON_ERROR_UNSUPPORTED_TYPE - assumed 'JSON_ERROR_UNSUPPORTED_TYPE' in /in/AHvH6 on line 32 Fatal error: Call to undefined function json_last_error() in /in/AHvH6 on line 34
Process exited with code 255.
Output for 5.3.0 - 5.3.2
Warning: json_encode() expects at most 2 parameters, 3 given in /in/AHvH6 on line 19 NULL Notice: Use of undefined constant JSON_ERROR_UTF8 - assumed 'JSON_ERROR_UTF8' in /in/AHvH6 on line 29 Notice: Use of undefined constant JSON_ERROR_RECURSION - assumed 'JSON_ERROR_RECURSION' in /in/AHvH6 on line 30 Notice: Use of undefined constant JSON_ERROR_INF_OR_NAN - assumed 'JSON_ERROR_INF_OR_NAN' in /in/AHvH6 on line 31 Notice: Use of undefined constant JSON_ERROR_UNSUPPORTED_TYPE - assumed 'JSON_ERROR_UNSUPPORTED_TYPE' in /in/AHvH6 on line 32 string(15) "JSON_ERROR_NONE"

preferences:
50.64 ms | 1167 KiB | 23 Q