1--TEST--
2Test session_set_save_handler() : implicit shutdown
3--INI--
4session.save_handler=files
5session.name=PHPSESSID
6--EXTENSIONS--
7session
8--SKIPIF--
9<?php include('skipif.inc'); ?>
10--FILE--
11<?php
12
13ob_start();
14
15echo "*** Testing session_set_save_handler() : implicit shutdown ***\n";
16
17class MySession extends SessionHandler {
18    public $num;
19    public function __construct($num) {
20        $this->num = $num;
21        echo "(#$this->num) constructor called\n";
22    }
23    public function __destruct() {
24        echo "(#$this->num) destructor called\n";
25    }
26    public function finish() {
27        $id = session_id();
28        echo "(#$this->num) finish called $id\n";
29        $this->shutdown();
30    }
31    public function write($id, $data): bool {
32        echo "(#$this->num) writing $id = $data\n";
33        return parent::write($id, $data);
34    }
35    public function close(): bool {
36        $id = session_id();
37        echo "(#$this->num) closing $id\n";
38        return parent::close();
39    }
40}
41
42$handler = new MySession(1);
43session_set_save_handler($handler);
44session_start();
45
46$_SESSION['foo'] = 'bar';
47
48// implicit close
49echo "done\n";
50ob_end_flush();
51?>
52--EXPECTF--
53*** Testing session_set_save_handler() : implicit shutdown ***
54(#1) constructor called
55done
56(#1) writing %s = foo|s:3:"bar";
57(#1) closing %s
58(#1) destructor called
59