1--TEST--
2Test session_set_save_handler() function: create_sid
3--INI--
4session.save_path="{TMP}"
5--EXTENSIONS--
6session
7--FILE--
8<?php
9
10ob_start();
11
12echo "*** Testing session_set_save_handler() function: create_sid ***\n";
13
14class MySession2 {
15    public $path;
16
17    public function open($path, $name): bool {
18        if (!$path) {
19            $path = sys_get_temp_dir();
20        }
21        $this->path = $path . '/u_sess_' . $name;
22        return true;
23    }
24
25    public function close(): bool {
26        return true;
27    }
28
29    public function read($id): string|false {
30        return @file_get_contents($this->path . $id);
31    }
32
33    public function write($id, $data): bool {
34        return file_put_contents($this->path . $id, $data);
35    }
36
37    public function destroy($id): bool {
38        @unlink($this->path . $id);
39        return false;
40    }
41
42    public function gc($maxlifetime): int|false {
43        foreach (glob($this->path . '*') as $filename) {
44            if (filemtime($filename) + $maxlifetime < time()) {
45                @unlink($filename);
46            }
47        }
48        return true;
49    }
50
51    #[ReturnTypeWillChange]
52    public function create_sid() {
53        return false;
54    }
55}
56
57$handler = new MySession2;
58session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
59    array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'), array($handler, 'create_sid'));
60session_start();
61
62$_SESSION['foo'] = "hello";
63
64var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
65
66session_write_close();
67session_unset();
68
69session_start();
70var_dump($_SESSION);
71
72session_write_close();
73session_unset();
74?>
75--EXPECTF--
76*** Testing session_set_save_handler() function: create_sid ***
77
78Fatal error: Uncaught Error: Session id must be a string in %s:%d
79Stack trace:
80#0 %s(%d): session_start()
81#1 {main}
82  thrown in %s on line %d
83