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