1--TEST--
2Test session_set_save_handler() : manual shutdown function
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 function ***\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, false);
42register_shutdown_function(array($handler, 'finish'));
43session_start();
44
45$_SESSION['foo'] = 'bar';
46
47echo "done\n";
48ob_end_flush();
49?>
50--EXPECTF--
51*** Testing session_set_save_handler() : manual shutdown function ***
52(#1) constructor called
53done
54(#1) finish called %s
55(#1) writing %s = foo|s:3:"bar";
56(#1) closing %s
57(#1) destructor called
58