File tree Expand file tree Collapse file tree
ext/session/tests/user_session_module Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ --TEST--
2+ session_regenerate_id(true): warns and returns false when save handler's destroy() fails
3+ --EXTENSIONS--
4+ session
5+ --INI--
6+ session.save_path=
7+ --FILE--
8+ <?php
9+
10+ class FailingDestroyHandler implements SessionHandlerInterface {
11+ function open ($ save_path , $ session_name ): bool {
12+ return true ;
13+ }
14+
15+ function close (): bool {
16+ return true ;
17+ }
18+
19+ function read ($ id ): string |false {
20+ return '' ;
21+ }
22+
23+ function write ($ id , $ session_data ): bool {
24+ return true ;
25+ }
26+
27+ function destroy ($ id ): bool {
28+ return false ;
29+ }
30+
31+ function gc ($ maxlifetime ): int |false {
32+ return 0 ;
33+ }
34+ }
35+
36+ session_set_save_handler (new FailingDestroyHandler ());
37+ session_start ();
38+ $ _SESSION ['foo ' ] = 'bar ' ;
39+ $ old_id = session_id ();
40+
41+ var_dump (session_regenerate_id (true ));
42+ var_dump (session_id () === $ old_id );
43+ var_dump (session_status () === PHP_SESSION_NONE );
44+
45+ ?>
46+ --EXPECTF--
47+ Warning: session_regenerate_id(): Session object destruction failed. ID: user (path: ) in %s on line %d
48+ bool(false)
49+ bool(true)
50+ bool(true)
Original file line number Diff line number Diff line change 1+ --TEST--
2+ session_regenerate_id(false): warns and returns false when save handler's write() fails
3+ --EXTENSIONS--
4+ session
5+ --INI--
6+ session.save_path=
7+ --FILE--
8+ <?php
9+
10+ class FailingWriteHandler implements SessionHandlerInterface {
11+ function open ($ save_path , $ session_name ): bool {
12+ return true ;
13+ }
14+
15+ function close (): bool {
16+ return true ;
17+ }
18+
19+ function read ($ id ): string |false {
20+ return '' ;
21+ }
22+
23+ function write ($ id , $ session_data ): bool {
24+ return false ;
25+ }
26+
27+ function destroy ($ id ): bool {
28+ return true ;
29+ }
30+
31+ function gc ($ maxlifetime ): int |false {
32+ return 0 ;
33+ }
34+ }
35+
36+ session_set_save_handler (new FailingWriteHandler ());
37+ session_start ();
38+ $ _SESSION ['foo ' ] = 'bar ' ;
39+ $ old_id = session_id ();
40+
41+ var_dump (session_regenerate_id (false ));
42+ var_dump (session_id () === $ old_id );
43+ var_dump (session_status () === PHP_SESSION_NONE );
44+
45+ ?>
46+ --EXPECTF--
47+ Warning: session_regenerate_id(): Session write failed. ID: user (path: ) in %s on line %d
48+ bool(false)
49+ bool(true)
50+ bool(true)
You can’t perform that action at this time.
0 commit comments