xref: /PHP-8.0/ext/session/tests/bug71162.phpt (revision f8d79582)
1--TEST--
2updateTimestamp never called when session data is empty
3--SKIPIF--
4<?php include('skipif.inc'); ?>
5--INI--
6session.use_strict_mode=0
7session.save_handler=files
8--XFAIL--
9Current session module is designed to write empty session always. In addition, current session module only supports SessionHandlerInterface only from PHP 7.0.
10--FILE--
11<?php
12class MySessionHandler extends SessionHandler implements SessionUpdateTimestampHandlerInterface
13{
14    public function open($path, $sessname) {
15        return TRUE;
16    }
17
18    public function close() {
19        return TRUE;
20    }
21
22    public function read($sessid) {
23        return '';
24    }
25
26    public function write($sessid, $sessdata) {
27        echo __FUNCTION__, PHP_EOL;
28        return TRUE;
29    }
30
31    public function destroy($sessid) {
32        return TRUE;
33    }
34
35    public function gc($maxlifetime) {
36        return TRUE;
37    }
38
39    public function create_sid() {
40        return sha1(random_bytes(32));
41    }
42
43    public function validateId($sid) {
44        return TRUE;
45    }
46
47    public function updateTimestamp($sessid, $sessdata) {
48        echo __FUNCTION__, PHP_EOL;
49        return TRUE;
50    }
51}
52
53ob_start();
54$handler = new MySessionHandler();
55session_set_save_handler($handler);
56
57session_id(sha1(''));
58var_dump(session_id());
59var_dump(session_start(['lazy_write'=>1]));
60session_commit();
61
62session_id(sha1(''));
63var_dump(session_id());
64var_dump(session_start(['lazy_write'=>1]));
65session_commit();
66
67session_id(sha1(''));
68var_dump(session_id());
69var_dump(session_start(['lazy_write'=>0]));
70session_commit();
71?>
72--EXPECT--
73string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
74bool(true)
75write
76string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
77bool(true)
78updateTimestamp
79string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
80bool(true)
81write
82