1--TEST--
2Test session_set_save_handler() : manual shutdown, reopen
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() : manual shutdown, reopen ***\n";
14
15class MySession extends SessionHandler {
16    public $num;
17    public function __construct($num) {
18        $this->num = $num;
19        echo "(#$this->num) constructor called\n";
20    }
21    public function __destruct() {
22        echo "(#$this->num) destructor called\n";
23    }
24    public function finish() {
25        $id = session_id();
26        echo "(#$this->num) finish called $id\n";
27        session_write_close();
28    }
29    public function write($id, $data): bool {
30        echo "(#$this->num) writing $id = $data\n";
31        return parent::write($id, $data);
32    }
33    public function close(): bool {
34        $id = session_id();
35        echo "(#$this->num) closing $id\n";
36        return parent::close();
37    }
38}
39
40$handler = new MySession(1);
41session_set_save_handler($handler);
42session_start();
43
44$_SESSION['foo'] = 'bar';
45
46// explicit close
47$handler->finish();
48
49$handler = new MySession(2);
50session_set_save_handler($handler);
51session_start();
52
53$_SESSION['abc'] = 'xyz';
54// implicit close (called by shutdown function)
55echo "done\n";
56ob_end_flush();
57?>
58--EXPECTF--
59*** Testing session_set_save_handler() : manual shutdown, reopen ***
60(#1) constructor called
61(#1) finish called %s
62(#1) writing %s = foo|s:3:"bar";
63(#1) closing %s
64(#2) constructor called
65(#1) destructor called
66done
67(#2) writing %s = foo|s:3:"bar";abc|s:3:"xyz";
68(#2) closing %s
69(#2) destructor called
70