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