1--TEST--
2Test session_encode() function : basic functionality
3--INI--
4serialize_precision=100
5--SKIPIF--
6<?php include('skipif.inc'); ?>
7--FILE--
8<?php
9
10ob_start();
11
12echo "*** Testing session_encode() : basic functionality ***\n";
13
14// Get an unset variable
15$unset_var = 10;
16unset($unset_var);
17
18class classA
19{
20    public function __toString() {
21        return "Hello World!";
22    }
23}
24
25$heredoc = <<<EOT
26Hello World!
27EOT;
28
29$fp = fopen(__FILE__, "r");
30
31// Unexpected values to be passed as arguments
32$inputs = array(
33
34       // Integer data
35/*1*/  0,
36       1,
37       12345,
38       -2345,
39
40       // Float data
41/*5*/  10.5,
42       -10.5,
43       12.3456789000e10,
44       12.3456789000E-10,
45       .5,
46
47       // Null data
48/*10*/ NULL,
49       null,
50
51       // Boolean data
52/*12*/ true,
53       false,
54       TRUE,
55       FALSE,
56
57       // Empty strings
58/*16*/ "",
59       '',
60
61       // Invalid string data
62/*18*/ "Nothing",
63       'Nothing',
64       $heredoc,
65
66       // Object data
67/*21*/ new classA(),
68
69       // Undefined data
70/*22*/ @$undefined_var,
71
72       // Unset data
73/*23*/ @$unset_var,
74
75       // Resource variable
76/*24*/ $fp
77);
78
79var_dump(session_start());
80$iterator = 1;
81foreach($inputs as $input) {
82    echo "\n-- Iteration $iterator --\n";
83    $_SESSION["data"] = $input;
84    var_dump(session_encode());
85    $iterator++;
86};
87
88var_dump(session_destroy());
89fclose($fp);
90echo "Done";
91ob_end_flush();
92?>
93--EXPECTF--
94*** Testing session_encode() : basic functionality ***
95bool(true)
96
97-- Iteration 1 --
98string(9) "data|i:0;"
99
100-- Iteration 2 --
101string(9) "data|i:1;"
102
103-- Iteration 3 --
104string(13) "data|i:12345;"
105
106-- Iteration 4 --
107string(13) "data|i:-2345;"
108
109-- Iteration 5 --
110string(12) "data|d:10.5;"
111
112-- Iteration 6 --
113string(13) "data|d:-10.5;"
114
115-- Iteration 7 --
116string(20) "data|d:123456789000;"
117
118-- Iteration 8 --
119string(%d) "data|d:1.2345678899999999145113427164344339914681114578343112953007221221923828125E-9;"
120
121-- Iteration 9 --
122string(11) "data|d:0.5;"
123
124-- Iteration 10 --
125string(7) "data|N;"
126
127-- Iteration 11 --
128string(7) "data|N;"
129
130-- Iteration 12 --
131string(9) "data|b:1;"
132
133-- Iteration 13 --
134string(9) "data|b:0;"
135
136-- Iteration 14 --
137string(9) "data|b:1;"
138
139-- Iteration 15 --
140string(9) "data|b:0;"
141
142-- Iteration 16 --
143string(12) "data|s:0:"";"
144
145-- Iteration 17 --
146string(12) "data|s:0:"";"
147
148-- Iteration 18 --
149string(19) "data|s:7:"Nothing";"
150
151-- Iteration 19 --
152string(19) "data|s:7:"Nothing";"
153
154-- Iteration 20 --
155string(25) "data|s:12:"Hello World!";"
156
157-- Iteration 21 --
158string(22) "data|O:6:"classA":0:{}"
159
160-- Iteration 22 --
161string(7) "data|N;"
162
163-- Iteration 23 --
164string(7) "data|N;"
165
166-- Iteration 24 --
167string(9) "data|i:0;"
168bool(true)
169Done
170