summaryrefslogtreecommitdiff
path: root/ext/json/tests/json_decode_basic.phpt
blob: d1169eb7777a6a0da46b799892d40a81794f3a5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
--TEST--
Test json_decode() function : basic functionality
--SKIPIF--
<?php if (!extension_loaded("json")) print "skip"; ?>
--FILE--
<?php
echo "*** Testing json_decode() : basic functionality ***\n";

// array with different values for $string
$inputs =  array (
	'0',
	'123',
	'-123',
	'2147483647',
	'-2147483648',
	'123.456',
	'1230',
	'-1230',
	'true',
	'false',
	'null',
	'"abc"',
	'"Hello World\r\n"',
	'[]',
	'[1,2,3,4,5]',
	'{"myInt":99,"myFloat":123.45,"myNull":null,"myBool":true,"myString":"Hello World"}',
	'{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}',
	'""',
	'{}'
);

// loop through with each element of the $inputs array to test json_decode() function
$count = 1;
foreach($inputs as $input) {
	echo "-- Iteration $count --\n";
	var_dump(json_decode($input));
	var_dump(json_decode($input, true));
	$count++;
}

?>
===Done===
--EXPECTF--
*** Testing json_decode() : basic functionality ***
-- Iteration 1 --
int(0)
int(0)
-- Iteration 2 --
int(123)
int(123)
-- Iteration 3 --
int(-123)
int(-123)
-- Iteration 4 --
int(2147483647)
int(2147483647)
-- Iteration 5 --
int(-2147483648)
int(-2147483648)
-- Iteration 6 --
float(123.456)
float(123.456)
-- Iteration 7 --
int(1230)
int(1230)
-- Iteration 8 --
int(-1230)
int(-1230)
-- Iteration 9 --
bool(true)
bool(true)
-- Iteration 10 --
bool(false)
bool(false)
-- Iteration 11 --
NULL
NULL
-- Iteration 12 --
string(3) "abc"
string(3) "abc"
-- Iteration 13 --
string(13) "Hello World
"
string(13) "Hello World
"
-- Iteration 14 --
array(0) {
}
array(0) {
}
-- Iteration 15 --
array(5) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
}
array(5) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
}
-- Iteration 16 --
object(stdClass)#%d (5) {
  ["myInt"]=>
  int(99)
  ["myFloat"]=>
  float(123.45)
  ["myNull"]=>
  NULL
  ["myBool"]=>
  bool(true)
  ["myString"]=>
  string(11) "Hello World"
}
array(5) {
  ["myInt"]=>
  int(99)
  ["myFloat"]=>
  float(123.45)
  ["myNull"]=>
  NULL
  ["myBool"]=>
  bool(true)
  ["myString"]=>
  string(11) "Hello World"
}
-- Iteration 17 --
object(stdClass)#%d (6) {
  ["Jan"]=>
  int(31)
  ["Feb"]=>
  int(29)
  ["Mar"]=>
  int(31)
  ["April"]=>
  int(30)
  ["May"]=>
  int(31)
  ["June"]=>
  int(30)
}
array(6) {
  ["Jan"]=>
  int(31)
  ["Feb"]=>
  int(29)
  ["Mar"]=>
  int(31)
  ["April"]=>
  int(30)
  ["May"]=>
  int(31)
  ["June"]=>
  int(30)
}
-- Iteration 18 --
string(0) ""
string(0) ""
-- Iteration 19 --
object(stdClass)#%d (0) {
}
array(0) {
}
===Done===