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; }

preferences:
43.86 ms | 407 KiB | 5 Q