1--TEST-- 2session_set_save_handler(): optional closures not set again in second call 3--INI-- 4session.use_strict_mode=1 5session.name=PHPSESSID 6session.serialize_handler=php_serialize 7--EXTENSIONS-- 8session 9--FILE-- 10<?php 11 12$data = []; 13 14ob_start(); 15function open($path, $name): bool { 16 echo 'Open', "\n"; 17 return true; 18} 19function create_sid(): string { 20 echo 'Create SID OLD', "\n"; 21 return 'OLD_ID'; 22} 23function read($key): string|false { 24 echo 'Read', "\n"; 25 global $data; 26 return serialize($data); 27} 28function write($key, $val): bool { 29 echo 'Write', "\n"; 30 global $data; 31 $data[$key] = $val; 32 return true; 33} 34function close(): bool { 35 echo 'Close', "\n"; 36 return true; 37} 38function destroy($id): bool { 39 echo 'Destroy', "\n"; 40 return true; 41} 42function gc($lifetime): bool { 43 return true; 44} 45function createSid(): string { 46 echo 'Create SID NEW', "\n"; 47 return 'NEW_ID'; 48} 49function validateId($key): bool { 50 echo 'Validate ID', "\n"; 51 return true; 52} 53function updateTimestamp($key, $data): bool { 54 echo 'Update Timestamp', "\n"; 55 return true; 56} 57 58session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc', 'create_sid', 'validateId', 'updateTimestamp'); 59session_start(); 60 61$_SESSION['foo'] = "hello"; 62 63session_write_close(); 64session_unset(); 65 66echo "New handlers:\n"; 67session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); 68session_start(); 69var_dump($_SESSION); 70$_SESSION['bar'] = "world"; 71session_write_close(); 72 73ob_end_flush(); 74?> 75--EXPECT-- 76Open 77Create SID OLD 78Read 79Write 80Close 81New handlers: 82Open 83Validate ID 84Read 85array(1) { 86 ["OLD_ID"]=> 87 string(28) "a:1:{s:3:"foo";s:5:"hello";}" 88} 89Write 90Close 91