xref: /PHP-8.0/ext/session/tests/bug78624.phpt (revision 7aacc705)
1--TEST--
2Test session_set_save_handler() : session_gc() returns the number of deleted records.
3--INI--
4session.name=PHPSESSID
5session.save_handler=files
6session.gc_probability=0
7--SKIPIF--
8<?php include('skipif.inc'); ?>
9--FILE--
10<?php
11
12ob_start();
13
14echo "*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***\n";
15
16class MySession implements SessionHandlerInterface {
17    public function open($path, $name) {
18        echo 'Open', "\n";
19        return true;
20    }
21    public function read($key) {
22        echo 'Read ', session_id(), "\n";
23        return '';
24    }
25    public function write($key, $data) {
26        echo 'Write ', session_id(), "\n";
27        return true;
28    }
29    public function close() {
30        echo 'Close ', session_id(), "\n";
31        return true;
32    }
33    public function destroy($key) {
34        echo 'Destroy ', session_id(), "\n";
35        return true;
36    }
37    public function gc($ts) {
38        echo 'Garbage collect', "\n";
39        return 1;
40    }
41}
42
43$handler = new MySession;
44session_set_save_handler($handler);
45session_start();
46var_dump(session_gc());
47session_write_close();
48
49?>
50--EXPECTF--
51*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***
52Open
53Read %s
54Garbage collect
55int(1)
56Write %s
57Close %s
58