xref: /PHP-7.4/ext/session/tests/bug78624.phpt (revision 7d19668f)
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
14/*
15 * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true])
16 * Description : Sets user-level session storage functions
17 * Source code : ext/session/session.c
18 */
19
20echo "*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***\n";
21
22class MySession implements SessionHandlerInterface {
23    public function open($path, $name) {
24        echo 'Open', "\n";
25        return true;
26    }
27    public function read($key) {
28        echo 'Read ', session_id(), "\n";
29        return '';
30    }
31    public function write($key, $data) {
32        echo 'Write ', session_id(), "\n";
33        return true;
34    }
35    public function close() {
36        echo 'Close ', session_id(), "\n";
37        return true;
38    }
39    public function destroy($key) {
40        echo 'Destroy ', session_id(), "\n";
41        return true;
42    }
43    public function gc($ts) {
44        echo 'Garbage collect', "\n";
45        return 1;
46    }
47}
48
49$handler = new MySession;
50session_set_save_handler($handler);
51session_start();
52var_dump(session_gc());
53session_write_close();
54
55--EXPECTF--
56*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***
57Open
58Read %s
59Garbage collect
60int(1)
61Write %s
62Close %s
63