3v4l.org

run code in 300+ PHP versions simultaneously
<?php $invalid = '{"test":"foo}'; $valid = '[]'; try { json_decode($invalid, true); // this fails silently json_decode($valid, true, 512, JSON_THROW_ON_ERROR); // Which is what Safe does to check if it needs to throw an exception if (json_last_error() !== JSON_ERROR_NONE) { var_dump('With the flag', json_last_error_msg()); } json_decode($valid, true); // Which is what Safe does to check if it needs to throw an exception if (json_last_error() !== JSON_ERROR_NONE) { var_dump('Without the flag', json_last_error_msg()); } } catch (Throwable $e) { echo 'This should not even be triggered: ' . $e->getMessage() . PHP_EOL; }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.23, 8.3.0 - 8.3.11
string(13) "With the flag" string(53) "Control character error, possibly incorrectly encoded"
Output for 7.2.0 - 7.2.34
Warning: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' (this will throw an Error in a future version of PHP) in /in/GX9mL on line 8 Warning: json_decode() expects parameter 4 to be integer, string given in /in/GX9mL on line 8 string(13) "With the flag" string(53) "Control character error, possibly incorrectly encoded"
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/GX9mL on line 8 Warning: json_decode() expects parameter 4 to be integer, string given in /in/GX9mL on line 8 string(13) "With the flag" string(53) "Control character error, possibly incorrectly encoded"
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/GX9mL on line 8 Warning: json_decode() expects parameter 4 to be long, string given in /in/GX9mL on line 8 string(13) "With the flag" string(12) "Syntax error"
Output for 5.4.0 - 5.4.45
Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/GX9mL on line 8 Warning: json_decode() expects parameter 4 to be long, string given in /in/GX9mL on line 8 Fatal error: Call to undefined function json_last_error_msg() in /in/GX9mL on line 12
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/GX9mL on line 8 Warning: json_decode() expects at most 3 parameters, 4 given in /in/GX9mL on line 8 Fatal error: Call to undefined function json_last_error_msg() in /in/GX9mL on line 12
Process exited with code 255.
Output for 5.2.0 - 5.2.17
Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/GX9mL on line 8 Warning: json_decode() expects at most 2 parameters, 4 given in /in/GX9mL on line 8 Fatal error: Call to undefined function json_last_error() in /in/GX9mL on line 11
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_decode() in /in/GX9mL on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/GX9mL on line 6
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 '{' in /in/GX9mL on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/GX9mL on line 6
Process exited with code 255.

preferences:
68.27 ms | 424 KiB | 6 Q