@ 2018-06-06T16:26:21Z <?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
try {
echo 'JSON decode of null: ' . json_decode(null) . PHP_EOL;
if (json_last_error() !== JSON_ERROR_NONE) {
echo 'Last JSON error: ' . safe_json_last_error_msg() . PHP_EOL;
}
} catch (Throwable $t) {
echo 'Error from JSON decode of null: ' . $t->getMessage() . PHP_EOL;
}
try {
echo 'JSON decode of empty string: ' . json_decode('') . PHP_EOL;
if (json_last_error() !== JSON_ERROR_NONE) {
echo 'Last JSON error: ' . safe_json_last_error_msg() . PHP_EOL;
}
} catch (Throwable $t) {
echo 'Error from JSON decode of empty string: ' . $t->getMessage() . PHP_EOL;
}
function safe_json_last_error_msg()
{
if (function_exists('json_last_error_msg')) {
return json_last_error_msg();
}
switch (json_last_error()) {
case JSON_ERROR_NONE: return 'No error';
case JSON_ERROR_DEPTH: return 'Maximum stack depth exceeded';
case JSON_ERROR_STATE_MISMATCH: return 'State mismatch (invalid or malformed JSON)';
case JSON_ERROR_CTRL_CHAR: return 'Control character error, possibly incorrectly encoded';
case JSON_ERROR_SYNTAX: return 'Syntax error';
case JSON_ERROR_UTF8: return 'Malformed UTF-8 characters, possibly incorrectly encoded';
default: return 'Unknown error';
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.33 , 8.2.0 - 8.2.29 , 8.3.0 - 8.3.25 , 8.4.1 - 8.4.12 Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in /in/aqapV on line 7
JSON decode of null:
Last JSON error: Syntax error
JSON decode of empty string:
Last JSON error: Syntax error
Output for 7.0.0 - 7.0.30 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 JSON decode of null:
Last JSON error: Syntax error
JSON decode of empty string:
Last JSON error: Syntax error
Output for 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.30 JSON decode of null:
JSON decode of empty string:
Output for 5.2.0 - 5.2.17 JSON decode of null:
Fatal error: Call to undefined function json_last_error() in /in/aqapV on line 9
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/aqapV on line 7
Process exited with code 255 . Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected '{' in /in/aqapV 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/aqapV on line 6
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/aqapV on line 6
Process exited with code 255 . preferences:dark mode live preview ace vim emacs key bindings
150.33 ms | 415 KiB | 5 Q