1--TEST-- 2Test session_set_save_handler() function: create_sid 3--INI-- 4session.save_path="{TMP}" 5--EXTENSIONS-- 6session 7--FILE-- 8<?php 9 10ob_start(); 11 12echo "*** Testing session_set_save_handler() function: create_sid ***\n"; 13 14class MySession2 implements SessionHandlerInterface, SessionIdInterface { 15 public $path; 16 17 public function open($path, $name): bool { 18 if (!$path) { 19 $path = sys_get_temp_dir(); 20 } 21 $this->path = $path . '/u_sess_' . $name; 22 return true; 23 } 24 25 public function close(): bool { 26 return true; 27 } 28 29 public function read($id): string|false { 30 return @file_get_contents($this->path . $id); 31 } 32 33 public function write($id, $data): bool { 34 return file_put_contents($this->path . $id, $data); 35 } 36 37 public function destroy($id): bool { 38 @unlink($this->path . $id); 39 return false; 40 } 41 42 public function gc($maxlifetime): int|false { 43 foreach (glob($this->path . '*') as $filename) { 44 if (filemtime($filename) + $maxlifetime < time()) { 45 @unlink($filename); 46 } 47 } 48 return true; 49 } 50 51 #[ReturnTypeWillChange] 52 public function create_sid() { 53 return false; 54 } 55} 56 57session_set_save_handler(new MySession2()); 58session_start(); 59 60$_SESSION['foo'] = "hello"; 61 62var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); 63 64session_write_close(); 65session_unset(); 66 67session_start(); 68var_dump($_SESSION); 69 70session_write_close(); 71session_unset(); 72?> 73--EXPECTF-- 74*** Testing session_set_save_handler() function: create_sid *** 75 76Fatal error: Uncaught Error: Session id must be a string in %s:%d 77Stack trace: 78#0 %s(%d): session_start() 79#1 {main} 80 thrown in %s on line %d 81