1--TEST--
2JSON_THROW_ON_ERROR: global error flag untouched
3--FILE--
4<?php
5
6var_dump(json_last_error());
7
8// here we cause a different kind of error to the following errors, so that
9// we can be sure the global error state looking unchanged isn't coincidence
10json_decode("\xFF");
11
12var_dump(json_last_error());
13
14try {
15    json_decode("", false, 512, JSON_THROW_ON_ERROR);
16} catch (JsonException $e) {
17    echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
18}
19
20var_dump(json_last_error());
21
22try {
23    json_decode("{", false, 512, JSON_THROW_ON_ERROR);
24} catch (JsonException $e) {
25    echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
26}
27
28var_dump(json_last_error());
29
30
31try {
32    json_encode(NAN, JSON_THROW_ON_ERROR);
33} catch (JsonException $e) {
34    echo "Caught JSON exception: ", $e->getCode(), PHP_EOL;
35}
36
37var_dump(json_last_error());
38
39?>
40--EXPECT--
41int(0)
42int(5)
43Caught JSON exception: 4
44int(5)
45Caught JSON exception: 4
46int(5)
47Caught JSON exception: 7
48int(5)
49