1--TEST-- 2Test session_set_save_handler() function: interface wrong 3--EXTENSIONS-- 4session 5--FILE-- 6<?php 7 8ob_start(); 9 10echo "*** Testing session_set_save_handler() function: interface wrong ***\n"; 11 12interface MySessionHandlerInterface { 13 public function open($path, $name): bool; 14 public function close(): bool; 15 public function read($id): string|false; 16 public function write($id, $data): bool; 17 public function destroy($id): bool; 18 public function gc($maxlifetime): int|false; 19} 20 21class MySession2 implements MySessionHandlerInterface { 22 public $path; 23 24 public function open($path, $name): bool { 25 if (!$path) { 26 $path = sys_get_temp_dir(); 27 } 28 $this->path = $path . '/u_sess_' . $name; 29 return true; 30 } 31 32 public function close(): bool { 33 return true; 34 } 35 36 public function read($id): string|false { 37 return (string)@file_get_contents($this->path . $id); 38 } 39 40 public function write($id, $data): bool { 41 echo "Unsupported session handler in use\n"; 42 return false; 43 } 44 45 public function destroy($id): bool { 46 @unlink($this->path . $id); 47 return true; 48 } 49 50 public function gc($maxlifetime): int|false { 51 foreach (glob($this->path . '*') as $filename) { 52 if (filemtime($filename) + $maxlifetime < time()) { 53 @unlink($filename); 54 } 55 } 56 57 return true; 58 } 59} 60 61function good_write($id, $data) { 62 global $handler; 63 echo "good handler writing\n"; 64 return file_put_contents($handler->path . $id, $data); 65} 66 67$handler = new MySession2; 68 69$ret = session_set_save_handler(array($handler, 'open'), array($handler, 'close'), 70 array($handler, 'read'), 'good_write', array($handler, 'destroy'), array($handler, 'gc')); 71 72var_dump($ret); 73try { 74 $ret = session_set_save_handler($handler); 75} catch (TypeError $e) { 76 echo $e->getMessage(), "\n"; 77} 78 79session_start(); 80?> 81--EXPECTF-- 82*** Testing session_set_save_handler() function: interface wrong *** 83 84Deprecated: session_set_save_handler(): Providing individual callbacks instead of an object implementing SessionHandlerInterface is deprecated in %s on line %d 85bool(true) 86session_set_save_handler(): Argument #1 ($open) must be of type SessionHandlerInterface, MySession2 given 87good handler writing 88 89Deprecated: PHP Request Shutdown: Session callback must have a return value of type bool, int returned in Unknown on line 0 90