1--TEST--
2Test json_encode() function : JSON_THROW_ON_ERROR flag
3--FILE--
4<?php
5
6try {
7    var_dump(json_encode("\x80", JSON_THROW_ON_ERROR));
8} catch (JsonException $e) {
9    var_dump($e);
10}
11
12// JSON_PARTIAL_OUTPUT_ON_ERROR is incompatible with exceptions
13// So it overrides it for the sake of working with wrappers that add the
14// JSON_THROW_ON_ERROR flag
15var_dump(json_encode("\x80", JSON_THROW_ON_ERROR | JSON_PARTIAL_OUTPUT_ON_ERROR));
16var_dump(json_last_error());
17var_dump(json_last_error_msg());
18
19?>
20--EXPECTF--
21object(JsonException)#1 (7) {
22  ["message":protected]=>
23  string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
24  ["string":"Exception":private]=>
25  string(0) ""
26  ["code":protected]=>
27  int(5)
28  ["file":protected]=>
29  string(%d) "%s"
30  ["line":protected]=>
31  int(%d)
32  ["trace":"Exception":private]=>
33  array(1) {
34    [0]=>
35    array(4) {
36      ["file"]=>
37      string(%d) "%s"
38      ["line"]=>
39      int(%d)
40      ["function"]=>
41      string(11) "json_encode"
42      ["args"]=>
43      array(2) {
44        [0]=>
45        string(1) "%s"
46        [1]=>
47        int(4194304)
48      }
49    }
50  }
51  ["previous":"Exception":private]=>
52  NULL
53}
54string(4) "null"
55int(5)
56string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
57