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