Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
--TEST-- JSON_THROW_ON_ERROR: global error flag untouched --FILE-- <?php var_dump(json_la..
Decoded Output download
--TEST--
JSON_THROW_ON_ERROR: global error flag untouched
--FILE--
<?php
var_dump(json_last_error());
// here we cause a different kind of error to the following errors, so that
// we can be sure the global error state looking unchanged isn't coincidence
json_decode("");
var_dump(json_last_error());
try {
json_decode("", false, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
}
var_dump(json_last_error());
try {
json_decode("{", false, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
}
var_dump(json_last_error());
try {
json_encode(NAN, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
}
var_dump(json_last_error());
?>
--EXPECT--
int(0)
int(5)
Caught JSON exception: 4
int(5)
Caught JSON exception: 4
int(5)
Caught JSON exception: 7
int(5)
Did this file decode correctly?
Original Code
--TEST--
JSON_THROW_ON_ERROR: global error flag untouched
--FILE--
<?php
var_dump(json_last_error());
// here we cause a different kind of error to the following errors, so that
// we can be sure the global error state looking unchanged isn't coincidence
json_decode("\xFF");
var_dump(json_last_error());
try {
json_decode("", false, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
}
var_dump(json_last_error());
try {
json_decode("{", false, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
}
var_dump(json_last_error());
try {
json_encode(NAN, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
}
var_dump(json_last_error());
?>
--EXPECT--
int(0)
int(5)
Caught JSON exception: 4
int(5)
Caught JSON exception: 4
int(5)
Caught JSON exception: 7
int(5)
Function Calls
json_last_error | 1 |
Stats
MD5 | a61382d579e393264f42c101a9d50810 |
Eval Count | 0 |
Decode Time | 96 ms |