xref: /PHP-8.0/ext/session/tests/gh9583-extra.phpt (revision 499fbcd6)
1--TEST--
2GH-9583: session_create_id() fails with user defined save handler that doesn't have a validateId() method
3--EXTENSIONS--
4session
5--SKIPIF--
6<?php include('skipif.inc'); ?>
7--FILE--
8<?php
9
10class SessionHandlerTester implements \SessionHandlerInterface
11{
12
13    public function close(): bool { return true; }
14
15    public function destroy($id): bool { return true; }
16
17    public function gc($max_lifetime): int|false { return 1; }
18
19    public function open($path, $name): bool { return true; }
20
21    public function read($id): string { return ''; }
22
23    public function write($id, $data): bool { return true; }
24
25    //public function create_sid() { return uniqid(); }
26
27    //public function validateId($key) { return true; }
28}
29
30$obj = new SessionHandlerTester();
31ini_set('session.use_strict_mode','1');
32session_set_save_handler($obj);
33session_start();
34
35$originalSessionId = session_id();
36
37session_write_close();
38
39session_start();
40
41$newSessionId = session_id();
42
43echo 'validateId() ', (method_exists($obj, 'validateId') ? ('returns ' . ($obj->validateId(1) ? 'true' : 'false')) : 'is commented out'), "\n";
44var_dump($originalSessionId == $newSessionId);
45
46?>
47--EXPECT--
48validateId() is commented out
49bool(true)
50