1--TEST--
2Test json_decode() function : basic functionality
3--FILE--
4<?php
5echo "*** Testing json_decode() : basic functionality ***\n";
6
7// array with different values for $string
8$inputs =  array (
9    '0',
10    '123',
11    '-123',
12    '2147483647',
13    '-2147483648',
14    '123.456',
15    '1230',
16    '-1230',
17    'true',
18    'false',
19    'null',
20    '"abc"',
21    '"Hello World\r\n"',
22    '[]',
23    '[1,2,3,4,5]',
24    '{"myInt":99,"myFloat":123.45,"myNull":null,"myBool":true,"myString":"Hello World"}',
25    '{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}',
26    '""',
27    '{}'
28);
29
30// loop through with each element of the $inputs array to test json_decode() function
31$count = 1;
32foreach($inputs as $input) {
33    echo "-- Iteration $count --\n";
34    var_dump(json_decode($input));
35    var_dump(json_decode($input, true));
36    $count++;
37}
38
39?>
40--EXPECTF--
41*** Testing json_decode() : basic functionality ***
42-- Iteration 1 --
43int(0)
44int(0)
45-- Iteration 2 --
46int(123)
47int(123)
48-- Iteration 3 --
49int(-123)
50int(-123)
51-- Iteration 4 --
52int(2147483647)
53int(2147483647)
54-- Iteration 5 --
55int(-2147483648)
56int(-2147483648)
57-- Iteration 6 --
58float(123.456)
59float(123.456)
60-- Iteration 7 --
61int(1230)
62int(1230)
63-- Iteration 8 --
64int(-1230)
65int(-1230)
66-- Iteration 9 --
67bool(true)
68bool(true)
69-- Iteration 10 --
70bool(false)
71bool(false)
72-- Iteration 11 --
73NULL
74NULL
75-- Iteration 12 --
76string(3) "abc"
77string(3) "abc"
78-- Iteration 13 --
79string(13) "Hello World
80"
81string(13) "Hello World
82"
83-- Iteration 14 --
84array(0) {
85}
86array(0) {
87}
88-- Iteration 15 --
89array(5) {
90  [0]=>
91  int(1)
92  [1]=>
93  int(2)
94  [2]=>
95  int(3)
96  [3]=>
97  int(4)
98  [4]=>
99  int(5)
100}
101array(5) {
102  [0]=>
103  int(1)
104  [1]=>
105  int(2)
106  [2]=>
107  int(3)
108  [3]=>
109  int(4)
110  [4]=>
111  int(5)
112}
113-- Iteration 16 --
114object(stdClass)#%d (5) {
115  ["myInt"]=>
116  int(99)
117  ["myFloat"]=>
118  float(123.45)
119  ["myNull"]=>
120  NULL
121  ["myBool"]=>
122  bool(true)
123  ["myString"]=>
124  string(11) "Hello World"
125}
126array(5) {
127  ["myInt"]=>
128  int(99)
129  ["myFloat"]=>
130  float(123.45)
131  ["myNull"]=>
132  NULL
133  ["myBool"]=>
134  bool(true)
135  ["myString"]=>
136  string(11) "Hello World"
137}
138-- Iteration 17 --
139object(stdClass)#%d (6) {
140  ["Jan"]=>
141  int(31)
142  ["Feb"]=>
143  int(29)
144  ["Mar"]=>
145  int(31)
146  ["April"]=>
147  int(30)
148  ["May"]=>
149  int(31)
150  ["June"]=>
151  int(30)
152}
153array(6) {
154  ["Jan"]=>
155  int(31)
156  ["Feb"]=>
157  int(29)
158  ["Mar"]=>
159  int(31)
160  ["April"]=>
161  int(30)
162  ["May"]=>
163  int(31)
164  ["June"]=>
165  int(30)
166}
167-- Iteration 18 --
168string(0) ""
169string(0) ""
170-- Iteration 19 --
171object(stdClass)#%d (0) {
172}
173array(0) {
174}
175