File: bug78624.phpt

package info (click to toggle)
php8.4 8.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 211,276 kB
  • sloc: ansic: 1,176,142; php: 35,419; sh: 11,964; cpp: 7,208; pascal: 4,951; javascript: 3,091; asm: 2,817; yacc: 2,411; makefile: 696; xml: 446; python: 301; awk: 148
file content (57 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--TEST--
Test session_set_save_handler() : session_gc() returns the number of deleted records.
--INI--
session.name=PHPSESSID
session.save_handler=files
session.gc_probability=0
--EXTENSIONS--
session
--FILE--
<?php

ob_start();

echo "*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***\n";

class MySession implements SessionHandlerInterface {
    public function open($path, $name): bool {
        echo 'Open', "\n";
        return true;
    }
    public function read($key): string|false {
        echo 'Read ', session_id(), "\n";
        return '';
    }
    public function write($key, $data): bool {
        echo 'Write ', session_id(), "\n";
        return true;
    }
    public function close(): bool {
        echo 'Close ', session_id(), "\n";
        return true;
    }
    public function destroy($key): bool {
        echo 'Destroy ', session_id(), "\n";
        return true;
    }
    public function gc($ts): int|false {
        echo 'Garbage collect', "\n";
        return 1;
    }
}

$handler = new MySession;
session_set_save_handler($handler);
session_start();
var_dump(session_gc());
session_write_close();

?>
--EXPECTF--
*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***
Open
Read %s
Garbage collect
int(1)
Write %s
Close %s