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