1--TEST--
2Test session_set_save_handler() function: class with 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: class with create_sid ***\n";
16
17class MySession2 extends SessionHandler {
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        return (bool)file_put_contents($this->path . $id, $data);
38    }
39
40    public function destroy($id): bool {
41        @unlink($this->path . $id);
42    }
43
44    public function gc($maxlifetime): int|false {
45        foreach (glob($this->path . '*') as $filename) {
46            if (filemtime($filename) + $maxlifetime < time()) {
47                @unlink($filename);
48            }
49        }
50        return true;
51    }
52
53    public function create_sid(): string {
54        return parent::create_sid();
55    }
56}
57
58$handler = new MySession2;
59session_set_save_handler($handler);
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: class with create_sid ***
77string(%d) "%s"
78string(4) "user"
79array(1) {
80  ["foo"]=>
81  string(5) "hello"
82}
83array(1) {
84  ["foo"]=>
85  string(5) "hello"
86}
87