1--TEST--
2Test session_set_save_handler() : basic class wrapping existing handler
3--INI--
4session.use_strict_mode=1
5session.name=PHPSESSID
6session.save_handler=files
7--EXTENSIONS--
8session
9--SKIPIF--
10<?php include('skipif.inc'); ?>
11--FILE--
12<?php
13
14ob_start();
15
16echo "*** Testing session_set_save_handler() : basic class wrapping existing handler ***\n";
17
18class MySession extends SessionHandler {
19    public $i = 0;
20    public function open($path, $name): bool {
21        ++$this->i;
22        echo 'Open ', session_id(), "\n";
23        return parent::open($path, $name);
24    }
25    public function create_sid(): string {
26        // This method should be removed when 5.5 become unsupported.
27        ++$this->i;
28        echo 'Old Create SID ', session_id(), "\n";
29        return parent::create_sid();
30    }
31    public function read($key): string|false {
32        ++$this->i;
33        echo 'Read ', session_id(), "\n";
34        return parent::read($key);
35    }
36    public function write($key, $data): bool {
37        ++$this->i;
38        echo 'Write ', session_id(), "\n";
39        return parent::write($key, $data);
40    }
41    public function close(): bool {
42        ++$this->i;
43        echo 'Close ', session_id(), "\n";
44        return parent::close();
45    }
46
47    public function createSid(): string {
48        // User should use this rather than create_sid()
49        // If both create_sid() and createSid() exists,
50        // createSid() is used.
51        ++$this->i;
52        echo 'New Create ID ', session_id(), "\n";
53        return parent::create_sid();
54    }
55    public function validateId($key): bool {
56        ++$this->i;
57        echo 'Validate ID ', session_id(), "\n";
58        return TRUE;
59        // User must implement their own method and
60        // cannot call parent as follows.
61        // return parent::validateSid($key);
62    }
63    public function updateTimestamp($key, $data): bool {
64        ++$this->i;
65        echo 'Update Timestamp ', session_id(), "\n";
66        return parent::write($key, $data);
67        // User must implement their own method and
68        // cannot call parent as follows
69        // return parent::updateTimestamp($key, $data);
70    }
71}
72
73$oldHandler = ini_get('session.save_handler');
74$handler = new MySession;
75session_set_save_handler($handler);
76session_start();
77
78var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i, $_SESSION);
79
80$_SESSION['foo'] = "hello";
81
82session_write_close();
83session_unset();
84
85session_start();
86var_dump($_SESSION);
87
88session_write_close();
89session_unset();
90var_dump($handler->i);
91?>
92--EXPECTF--
93*** Testing session_set_save_handler() : basic class wrapping existing handler ***
94Open
95Old Create SID
96Read %s
97string(%d) "%s"
98string(5) "files"
99string(4) "user"
100int(3)
101array(0) {
102}
103Write %s
104Close %s
105Open %s
106Validate ID %s
107Read %s
108array(1) {
109  ["foo"]=>
110  string(5) "hello"
111}
112Update Timestamp %s
113Close %s
114int(10)
115