1--TEST--
2Test json_decode() function : basic functionality
3--SKIPIF--
4<?php
5if (!extension_loaded("json")) {
6 	die('skip JSON extension not available in this build');
7}
8?>
9--FILE--
10<?php
11/* Prototype  : mixed json_decode  ( string $json  [, bool $assoc  ] )
12 * Description: Decodes a JSON string
13 * Source code: ext/json/php_json.c
14 * Alias to functions:
15 */
16echo "*** Testing json_decode() : basic functionality ***\n";
17
18// array with different values for $string
19$inputs =  array (
20		'0',
21		'123',
22		'-123',
23		'2147483647',
24		'-2147483648',
25		'123.456',
26		'1230',
27		'-1230',
28		'true',
29		'false',
30		'null',
31		'"abc"',
32		'"Hello World\r\n"',
33		'[]',
34		'[1,2,3,4,5]',
35		'{"myInt":99,"myFloat":123.45,"myNull":null,"myBool":true,"myString":"Hello World"}',
36		'{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}',
37		'""',
38		'{}'
39);
40
41// loop through with each element of the $inputs array to test json_decode() function
42$count = 1;
43foreach($inputs as $input) {
44  echo "-- Iteration $count --\n";
45  var_dump(json_decode($input));
46   var_dump(json_decode($input, TRUE));
47  $count ++;
48}
49
50?>
51===Done===
52--EXPECTF--
53*** Testing json_decode() : basic functionality ***
54-- Iteration 1 --
55int(0)
56int(0)
57-- Iteration 2 --
58int(123)
59int(123)
60-- Iteration 3 --
61int(-123)
62int(-123)
63-- Iteration 4 --
64int(2147483647)
65int(2147483647)
66-- Iteration 5 --
67int(-2147483648)
68int(-2147483648)
69-- Iteration 6 --
70float(123.456)
71float(123.456)
72-- Iteration 7 --
73int(1230)
74int(1230)
75-- Iteration 8 --
76int(-1230)
77int(-1230)
78-- Iteration 9 --
79bool(true)
80bool(true)
81-- Iteration 10 --
82bool(false)
83bool(false)
84-- Iteration 11 --
85NULL
86NULL
87-- Iteration 12 --
88string(3) "abc"
89string(3) "abc"
90-- Iteration 13 --
91string(13) "Hello World
92"
93string(13) "Hello World
94"
95-- Iteration 14 --
96array(0) {
97}
98array(0) {
99}
100-- Iteration 15 --
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}
113array(5) {
114  [0]=>
115  int(1)
116  [1]=>
117  int(2)
118  [2]=>
119  int(3)
120  [3]=>
121  int(4)
122  [4]=>
123  int(5)
124}
125-- Iteration 16 --
126object(stdClass)#%d (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}
138array(5) {
139  ["myInt"]=>
140  int(99)
141  ["myFloat"]=>
142  float(123.45)
143  ["myNull"]=>
144  NULL
145  ["myBool"]=>
146  bool(true)
147  ["myString"]=>
148  string(11) "Hello World"
149}
150-- Iteration 17 --
151object(stdClass)#%d (6) {
152  ["Jan"]=>
153  int(31)
154  ["Feb"]=>
155  int(29)
156  ["Mar"]=>
157  int(31)
158  ["April"]=>
159  int(30)
160  ["May"]=>
161  int(31)
162  ["June"]=>
163  int(30)
164}
165array(6) {
166  ["Jan"]=>
167  int(31)
168  ["Feb"]=>
169  int(29)
170  ["Mar"]=>
171  int(31)
172  ["April"]=>
173  int(30)
174  ["May"]=>
175  int(31)
176  ["June"]=>
177  int(30)
178}
179-- Iteration 18 --
180string(0) ""
181string(0) ""
182-- Iteration 19 --
183object(stdClass)#%d (0) {
184}
185array(0) {
186}
187===Done===
188