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