1--TEST-- 2Test session_set_save_handler() function: create_sid 3--EXTENSIONS-- 4session 5--FILE-- 6<?php 7 8ob_start(); 9 10echo "*** Testing session_set_save_handler() function: create_sid ***\n"; 11 12class MySession2 { 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 return true; 47 } 48 49 public function create_sid(): string { 50 return pathinfo(__FILE__)['filename']; 51 } 52} 53 54$handler = new MySession2; 55session_set_save_handler(array($handler, 'open'), array($handler, 'close'), 56 array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'), array($handler, 'create_sid')); 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_sid_001'); 72?> 73--EXPECTF-- 74*** Testing session_set_save_handler() function: create_sid *** 75 76Deprecated: Calling session_set_save_handler() with more than 2 arguments is deprecated in %s on line %d 77string(32) "session_set_save_handler_sid_001" 78string(4) "user" 79array(1) { 80 ["foo"]=> 81 string(5) "hello" 82} 83array(1) { 84 ["foo"]=> 85 string(5) "hello" 86} 87