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