xref: /PHP-8.4/ext/json/tests/007.phpt (revision 32a1ebbd)
1--TEST--
2json_last_error() tests
3--FILE--
4<?php
5var_dump(json_decode("[1]"));
6var_dump(json_last_error(), json_last_error_msg());
7var_dump(json_decode("[[1]]", false, 2));
8var_dump(json_last_error(), json_last_error_msg());
9var_dump(json_decode("[1}"));
10var_dump(json_last_error(), json_last_error_msg());
11var_dump(json_decode('["' . chr(0) . 'abcd"]'));
12var_dump(json_last_error(), json_last_error_msg());
13var_dump(json_decode("[1"));
14var_dump(json_last_error(), json_last_error_msg());
15
16echo "Done\n";
17?>
18--EXPECT--
19array(1) {
20  [0]=>
21  int(1)
22}
23int(0)
24string(8) "No error"
25NULL
26int(1)
27string(28) "Maximum stack depth exceeded"
28NULL
29int(2)
30string(42) "State mismatch (invalid or malformed JSON)"
31NULL
32int(3)
33string(53) "Control character error, possibly incorrectly encoded"
34NULL
35int(4)
36string(12) "Syntax error"
37Done
38