Files
php-src/ext/session/tests/session_reset_handler_close.phpt
Ilia Alshanetsky c65321c70f session: close the save handler before session_reset() reopens it (#23597)
php_session_reset() called php_session_initialize() on an already active
session, so the save handler's open() and read() ran a second time with no
intervening close(). Abort the session first, pairing every open() with a
close().

Closes GH-23597
2026-10-13 15:35:12 -04:00

75 lines
1.5 KiB
PHP

--TEST--
Session reset closes the save handler before reopening it
--EXTENSIONS--
session
--INI--
session.use_cookies=0
session.gc_probability=0
--FILE--
<?php
class LoggingHandler implements SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface
{
public function open(string $path, string $name): bool
{
$GLOBALS['calls'][] = 'open';
return true;
}
public function close(): bool
{
$GLOBALS['calls'][] = 'close';
return true;
}
public function read(string $id): string|false
{
$GLOBALS['calls'][] = 'read';
return '';
}
public function write(string $id, string $data): bool
{
$GLOBALS['calls'][] = 'write';
return true;
}
public function destroy(string $id): bool
{
$GLOBALS['calls'][] = 'destroy';
return true;
}
public function gc(int $max_lifetime): int|false
{
$GLOBALS['calls'][] = 'gc';
return 0;
}
public function create_sid(): string
{
return 'testsessionid';
}
public function validateId(string $id): bool
{
return true;
}
public function updateTimestamp(string $id, string $data): bool
{
return true;
}
}
$GLOBALS['calls'] = [];
session_set_save_handler(new LoggingHandler(), true);
var_dump(session_start());
var_dump(session_reset());
print_r($GLOBALS['calls']);
?>
--EXPECT--
bool(true)
bool(true)
Array
(
[0] => open
[1] => read
[2] => close
[3] => open
[4] => read
)