1--TEST--
2Test session_encode() function : error functionality
3--SKIPIF--
4<?php include('skipif.inc'); ?>
5--FILE--
6<?php
7
8ob_start();
9
10echo "*** Testing session_encode() : error functionality ***\n";
11
12// Get an unset variable
13$unset_var = 10;
14unset($unset_var);
15
16class classA
17{
18    public function __toString() {
19        return "Hello World!";
20    }
21}
22
23$heredoc = <<<EOT
24Hello World!
25EOT;
26
27$fp = fopen(__FILE__, "r");
28
29// Unexpected values to be passed as arguments
30$inputs = array(
31
32       // Integer data
33/*1*/  0,
34       1,
35       12345,
36       -2345,
37
38       // Float data
39/*5*/  10.5,
40       -10.5,
41       12.3456789000e10,
42       12.3456789000E-10,
43       .5,
44
45       // Null data
46/*10*/ NULL,
47       null,
48
49       // Boolean data
50/*12*/ true,
51       false,
52       TRUE,
53       FALSE,
54
55       // Empty strings
56/*16*/ "",
57       '',
58
59       // Invalid string data
60/*18*/ "Nothing",
61       'Nothing',
62       $heredoc,
63
64       // Object data
65/*21*/ new classA(),
66
67       // Undefined data
68/*22*/ @$undefined_var,
69
70       // Unset data
71/*23*/ @$unset_var,
72
73       // Resource variable
74/*24*/ $fp
75);
76
77$iterator = 1;
78foreach($inputs as $input) {
79    echo "\n-- Iteration $iterator --\n";
80    var_dump(session_start());
81    try {
82        $_SESSION[$input] = "Hello World!";
83    } catch (Error $e) {
84        echo $e->getMessage(), "\n";
85    }
86    var_dump(session_encode());
87    var_dump(session_destroy());
88    $iterator++;
89};
90
91fclose($fp);
92echo "Done";
93ob_end_flush();
94?>
95--EXPECTF--
96*** Testing session_encode() : error functionality ***
97
98-- Iteration 1 --
99bool(true)
100
101Warning: session_encode(): Skipping numeric key 0 in %s on line %d
102bool(false)
103bool(true)
104
105-- Iteration 2 --
106bool(true)
107
108Warning: session_encode(): Skipping numeric key 1 in %s on line %d
109bool(false)
110bool(true)
111
112-- Iteration 3 --
113bool(true)
114
115Warning: session_encode(): Skipping numeric key 12345 in %s on line %d
116bool(false)
117bool(true)
118
119-- Iteration 4 --
120bool(true)
121
122Warning: session_encode(): Skipping numeric key -2345 in %s on line %d
123bool(false)
124bool(true)
125
126-- Iteration 5 --
127bool(true)
128
129Warning: session_encode(): Skipping numeric key 10 in %s on line %d
130bool(false)
131bool(true)
132
133-- Iteration 6 --
134bool(true)
135
136Warning: session_encode(): Skipping numeric key -10 in %s on line %d
137bool(false)
138bool(true)
139
140-- Iteration 7 --
141bool(true)
142
143Warning: session_encode(): Skipping numeric key %s in %s on line %d
144bool(false)
145bool(true)
146
147-- Iteration 8 --
148bool(true)
149
150Warning: session_encode(): Skipping numeric key 0 in %s on line %d
151bool(false)
152bool(true)
153
154-- Iteration 9 --
155bool(true)
156
157Warning: session_encode(): Skipping numeric key 0 in %s on line %d
158bool(false)
159bool(true)
160
161-- Iteration 10 --
162bool(true)
163string(21) "|s:12:"Hello World!";"
164bool(true)
165
166-- Iteration 11 --
167bool(true)
168string(21) "|s:12:"Hello World!";"
169bool(true)
170
171-- Iteration 12 --
172bool(true)
173
174Warning: session_encode(): Skipping numeric key 1 in %s on line %d
175bool(false)
176bool(true)
177
178-- Iteration 13 --
179bool(true)
180
181Warning: session_encode(): Skipping numeric key 0 in %s on line %d
182bool(false)
183bool(true)
184
185-- Iteration 14 --
186bool(true)
187
188Warning: session_encode(): Skipping numeric key 1 in %s on line %d
189bool(false)
190bool(true)
191
192-- Iteration 15 --
193bool(true)
194
195Warning: session_encode(): Skipping numeric key 0 in %s on line %d
196bool(false)
197bool(true)
198
199-- Iteration 16 --
200bool(true)
201string(21) "|s:12:"Hello World!";"
202bool(true)
203
204-- Iteration 17 --
205bool(true)
206string(21) "|s:12:"Hello World!";"
207bool(true)
208
209-- Iteration 18 --
210bool(true)
211string(28) "Nothing|s:12:"Hello World!";"
212bool(true)
213
214-- Iteration 19 --
215bool(true)
216string(28) "Nothing|s:12:"Hello World!";"
217bool(true)
218
219-- Iteration 20 --
220bool(true)
221string(33) "Hello World!|s:12:"Hello World!";"
222bool(true)
223
224-- Iteration 21 --
225bool(true)
226Illegal offset type
227bool(false)
228bool(true)
229
230-- Iteration 22 --
231bool(true)
232string(21) "|s:12:"Hello World!";"
233bool(true)
234
235-- Iteration 23 --
236bool(true)
237string(21) "|s:12:"Hello World!";"
238bool(true)
239
240-- Iteration 24 --
241bool(true)
242
243Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
244
245Warning: session_encode(): Skipping numeric key %d in %s on line %d
246bool(false)
247bool(true)
248Done
249