[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Tue, 13 Oct 2026 18:44:08 +0000
Subject: [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142241@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-10-13T14:39:10-04:00 Commit: https://github.com/php/php-src/commit/5ede5b163e96fed8110fd371eef8bce83e41b54f Raw diff: https://github.com/php/php-src/commit/5ede5b163e96fed8110fd371eef8bce83e41b54f.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: ext/session: do not reuse session state a save handler tore down Changed paths: A ext/session/tests/user_session_module/session_regenerate_id_handler_closes_session.phpt A ext/session/tests/user_session_module/session_regenerate_id_handler_destroys_session.phpt M ext/session/session.c Diff: diff --git a/ext/session/session.c b/ext/session/session.c index 0ee8c94cf33e..701f15309e4f 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -2403,8 +2403,14 @@ PHP_FUNCTION(session_regenerate_id) RETURN_FALSE; } } + PS(mod)->s_close(&PS(mod_data)); + if (PS(session_status) != php_session_active) { + php_error_docref(NULL, E_WARNING, "Session ID cannot be regenerated because the save handler closed the session"); + RETURN_FALSE; + } + /* New session data */ if (PS(session_vars)) { zend_string_release_ex(PS(session_vars), false); diff --git a/ext/session/tests/user_session_module/session_regenerate_id_handler_closes_session.phpt b/ext/session/tests/user_session_module/session_regenerate_id_handler_closes_session.phpt new file mode 100644 index 000000000000..80b4471d60f1 --- /dev/null +++ b/ext/session/tests/user_session_module/session_regenerate_id_handler_closes_session.phpt @@ -0,0 +1,73 @@ +--TEST-- +session_regenerate_id() when the close handler destroys the session +--INI-- +session.gc_probability=0 +--EXTENSIONS-- +session +--FILE-- +<?php + +ob_start(); + +class MySessionHandler implements SessionHandlerInterface +{ + private bool $destroyed = false; + + public function open(string $path, string $name): bool + { + return true; + } + + public function close(): bool + { + if (!$this->destroyed) { + $this->destroyed = true; + session_destroy(); + } + return true; + } + + public function read(string $id): string|false + { + return ''; + } + + public function write(string $id, string $data): bool + { + return true; + } + + public function destroy(string $id): bool + { + return true; + } + + public function gc(int $max_lifetime): int|false + { + return 0; + } +} + +session_set_save_handler(new MySessionHandler(), true); +session_start(); + +var_dump(session_regenerate_id(false)); +var_dump(session_status() === PHP_SESSION_NONE); + +?> +--EXPECTF-- +Warning: Class MySessionHandler implementing SessionHandlerInterface is missing the create_sid() method which will be required in PHP 9.0 in %s on line %d + +Warning: Class MySessionHandler implementing SessionHandlerInterface is missing the validateId() method which will be required in PHP 9.0 in %s on line %d + +Deprecated: session_set_save_handler(): Providing an object to argument #1 ($sessionhandler) which does not have the create_sid() method defined is deprecated in %s on line %d + +Deprecated: session_set_save_handler(): Providing an object to argument #1 ($sessionhandler) which does not have the validateId() method defined is deprecated in %s on line %d + +Warning: session_destroy(): Cannot call session save handler in a recursive manner in %s on line %d + +Warning: session_destroy(): Session object destruction failed in %s on line %d + +Warning: session_regenerate_id(): Session ID cannot be regenerated because the save handler closed the session in %s on line %d +bool(false) +bool(true) diff --git a/ext/session/tests/user_session_module/session_regenerate_id_handler_destroys_session.phpt b/ext/session/tests/user_session_module/session_regenerate_id_handler_destroys_session.phpt new file mode 100644 index 000000000000..d7b5007ce1fc --- /dev/null +++ b/ext/session/tests/user_session_module/session_regenerate_id_handler_destroys_session.phpt @@ -0,0 +1,35 @@ +--TEST-- +session_regenerate_id() when the save handler destroys the session +--INI-- +session.gc_probability=0 +--EXTENSIONS-- +session +--FILE-- +<?php + +ob_start(); + +class MySessionHandler extends SessionHandler +{ + public function destroy(string $id): bool + { + session_destroy(); + return true; + } +} + +session_set_save_handler(new MySessionHandler(), true); +session_start(); + +var_dump(session_regenerate_id(true)); +var_dump(session_status() === PHP_SESSION_NONE); + +?> +--EXPECTF-- +Warning: session_destroy(): Cannot call session save handler in a recursive manner in %s on line %d + +Warning: session_destroy(): Session object destruction failed in %s on line %d + +Warning: session_regenerate_id(): Session ID cannot be regenerated because the save handler closed the session in %s on line %d +bool(false) +bool(true)

« previous php.cvs (#142241) next »