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