1--TEST--
2GH-7787: Provide more SessionHandler failure information
3--EXTENSIONS--
4session
5--INI--
6session.use_strict_mode=0
7--FILE--
8<?php
9class MySessionHandler extends SessionHandler implements SessionUpdateTimestampHandlerInterface
10{
11    public function open($path, $sessname): bool {
12        return true;
13    }
14
15    public function close(): bool {
16        return true;
17    }
18
19    public function read($sessid): string|false {
20        return 'foo|s:3:"foo";';
21    }
22
23    public function write($sessid, $sessdata): bool {
24        return false;
25    }
26
27    public function destroy($sessid): bool {
28        return true;
29    }
30
31    public function gc($maxlifetime): int|false {
32        return true;
33    }
34
35    public function create_sid(): string {
36        return sha1(random_bytes(32));
37    }
38
39    public function validateId($sid): bool {
40        return true;
41    }
42
43    public function updateTimestamp($sessid, $sessdata): bool {
44        return false;
45    }
46}
47
48ob_start();
49
50$handler = new MySessionHandler();
51session_set_save_handler($handler);
52
53session_start();
54$_SESSION['foo'] = 'bar';
55session_write_close();
56
57session_start();
58session_write_close();
59
60session_set_save_handler(
61    fn() => true,
62    fn() => true,
63    fn() => 'foo|s:3:"foo";',
64    fn() => false,
65    fn() => true,
66    fn() => true,
67    fn() => sha1(random_bytes(32)),
68    fn() => true,
69    fn() => false,
70);
71
72session_start();
73$_SESSION['foo'] = 'bar';
74session_write_close();
75
76session_start();
77session_write_close();
78
79?>
80--EXPECTF--
81Warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: %S, handler: MySessionHandler::write) in %s on line %d
82
83Warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: %S, handler: MySessionHandler::updateTimestamp) in %s on line %d
84
85Warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: %S, handler: write) in %s on line %d
86
87Warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: %S, handler: update_timestamp) in %s on line %d
88