1--TEST--
2Test json_encode() function : basic functionality
3--FILE--
4<?php
5echo "*** Testing json_encode() : basic functionality ***\n";
6
7//get an unset variable
8$unset_var = 10;
9unset ($unset_var);
10
11// get a resource variable
12$fp = fopen(__FILE__, "r");
13
14// get an object
15$obj = new stdClass();
16$obj->MyInt = 99;
17$obj->MyFloat = 123.45;
18$obj->MyBool = true;
19$obj->MyNull = null;
20$obj->MyString = "Hello World";
21
22// array with different values for $string
23$inputs =  array (
24    // integers
25    0,
26    123,
27    -123,
28     2147483647,
29    -2147483648,
30
31    // floats
32    123.456,
33    1.23E3,
34    -1.23E3,
35
36    // boolean
37    TRUE,
38    true,
39    FALSE,
40    false,
41
42    // NULL
43    NULL,
44    null,
45
46    // strings
47    "abc",
48    'abc',
49    "Hello\t\tWorld\n",
50
51    // arrays
52    array(),
53    array(1,2,3,4,5),
54    array(1 => "Sun", 2 => "Mon", 3 => "Tue", 4 => "Wed", 5 => "Thur", 6 => "Fri", 7 => "Sat"),
55    array("Jan" => 31, "Feb" => 29, "Mar" => 31, "April" => 30, "May" => 31, "June" => 30),
56
57    // empty data
58    "",
59    '',
60
61    // undefined data
62    @$undefined_var,
63
64    // unset data
65    @$unset_var,
66
67    // resource variable
68    $fp,
69
70    // object variable
71    $obj
72
73);
74
75// loop through with each element of the $inputs array to test json_encode() function
76$count = 1;
77foreach($inputs as $input) {
78    echo "-- Iteration $count --\n";
79    var_dump(json_encode($input));
80    $count ++;
81}
82
83?>
84--EXPECT--
85*** Testing json_encode() : basic functionality ***
86-- Iteration 1 --
87string(1) "0"
88-- Iteration 2 --
89string(3) "123"
90-- Iteration 3 --
91string(4) "-123"
92-- Iteration 4 --
93string(10) "2147483647"
94-- Iteration 5 --
95string(11) "-2147483648"
96-- Iteration 6 --
97string(7) "123.456"
98-- Iteration 7 --
99string(4) "1230"
100-- Iteration 8 --
101string(5) "-1230"
102-- Iteration 9 --
103string(4) "true"
104-- Iteration 10 --
105string(4) "true"
106-- Iteration 11 --
107string(5) "false"
108-- Iteration 12 --
109string(5) "false"
110-- Iteration 13 --
111string(4) "null"
112-- Iteration 14 --
113string(4) "null"
114-- Iteration 15 --
115string(5) ""abc""
116-- Iteration 16 --
117string(5) ""abc""
118-- Iteration 17 --
119string(18) ""Hello\t\tWorld\n""
120-- Iteration 18 --
121string(2) "[]"
122-- Iteration 19 --
123string(11) "[1,2,3,4,5]"
124-- Iteration 20 --
125string(72) "{"1":"Sun","2":"Mon","3":"Tue","4":"Wed","5":"Thur","6":"Fri","7":"Sat"}"
126-- Iteration 21 --
127string(58) "{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}"
128-- Iteration 22 --
129string(2) """"
130-- Iteration 23 --
131string(2) """"
132-- Iteration 24 --
133string(4) "null"
134-- Iteration 25 --
135string(4) "null"
136-- Iteration 26 --
137bool(false)
138-- Iteration 27 --
139string(82) "{"MyInt":99,"MyFloat":123.45,"MyBool":true,"MyNull":null,"MyString":"Hello World"}"
140