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