1--TEST--
2Test session_set_save_handler(): Session Handler inheritance
3--INI--
4session.save_handler=files
5session.name=PHPSESSID
6--EXTENSIONS--
7session
8--FILE--
9<?php
10
11ob_start();
12
13echo "*** Testing session_set_save_handler() : inheritance ***\n";
14
15class MySession3 extends SessionHandler {
16    public $i = 0;
17    public function open($path, $name): bool {
18        ++$this->i;
19        return parent::open($path, $name);
20    }
21    public function read($key): string|false {
22        ++$this->i;
23        return parent::read($key);
24    }
25}
26
27class MySession4 extends MySession3 {
28    public function write($id, $data): bool {
29        $this->i = "hai";
30        return parent::write($id, $data);
31    }
32}
33
34$handler = new MySession3;
35session_set_save_handler($handler);
36session_start();
37
38$_SESSION['foo'] = "hello";
39
40session_write_close();
41session_unset();
42
43session_start();
44
45var_dump($_SESSION, $handler->i);
46
47session_write_close();
48session_unset();
49
50$handler = new MySession4;
51session_set_save_handler($handler);
52
53session_start();
54
55$_SESSION['bar'] = 'hello';
56session_write_close();
57session_unset();
58
59var_dump(session_id(), $_SESSION, $handler->i);
60?>
61--EXPECTF--
62*** Testing session_set_save_handler() : inheritance ***
63array(1) {
64  ["foo"]=>
65  string(5) "hello"
66}
67int(4)
68string(%d) "%s"
69array(2) {
70  ["foo"]=>
71  string(5) "hello"
72  ["bar"]=>
73  string(5) "hello"
74}
75string(3) "hai"
76