Skip to content

Commit 15c0df7

Browse files
committed
Add regression test for not setting optional closures again
1 parent 5465eff commit 15c0df7

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
--TEST--
2+
session_set_save_handler(): optional closures not set again in second call
3+
--INI--
4+
session.use_strict_mode=1
5+
session.name=PHPSESSID
6+
session.serialize_handler=php_serialize
7+
--EXTENSIONS--
8+
session
9+
--FILE--
10+
<?php
11+
12+
$data = [];
13+
14+
ob_start();
15+
function open($path, $name): bool {
16+
echo 'Open', "\n";
17+
return true;
18+
}
19+
function create_sid(): string {
20+
echo 'Create SID OLD', "\n";
21+
return 'OLD_ID';
22+
}
23+
function read($key): string|false {
24+
echo 'Read', "\n";
25+
global $data;
26+
return serialize($data);
27+
}
28+
function write($key, $val): bool {
29+
echo 'Write', "\n";
30+
global $data;
31+
$data[$key] = $val;
32+
return true;
33+
}
34+
function close(): bool {
35+
echo 'Close', "\n";
36+
return true;
37+
}
38+
function destroy($id): bool {
39+
echo 'Destroy', "\n";
40+
return true;
41+
}
42+
function gc($lifetime): bool {
43+
return true;
44+
}
45+
function createSid(): string {
46+
echo 'Create SID NEW', "\n";
47+
return 'NEW_ID';
48+
}
49+
function validateId($key): bool {
50+
echo 'Validate ID', "\n";
51+
return true;
52+
}
53+
function updateTimestamp($key, $data): bool {
54+
echo 'Update Timestamp', "\n";
55+
return true;
56+
}
57+
58+
session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc', 'create_sid', 'validateId', 'updateTimestamp');
59+
session_start();
60+
61+
$_SESSION['foo'] = "hello";
62+
63+
session_write_close();
64+
session_unset();
65+
66+
echo "New handlers:\n";
67+
session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
68+
session_start();
69+
var_dump($_SESSION);
70+
$_SESSION['bar'] = "world";
71+
session_write_close();
72+
73+
ob_end_flush();
74+
?>
75+
--EXPECT--
76+
Open
77+
Create SID OLD
78+
Read
79+
Write
80+
Close
81+
New handlers:
82+
Open
83+
Validate ID
84+
Read
85+
array(1) {
86+
["OLD_ID"]=>
87+
string(28) "a:1:{s:3:"foo";s:5:"hello";}"
88+
}
89+
Write
90+
Close

0 commit comments

Comments
 (0)