1--TEST-- 2Test session_set_save_handler() function: interface wrong 3--INI-- 4session.save_handler=files 5session.name=PHPSESSID 6--SKIPIF-- 7<?php include('skipif.inc'); ?> 8--FILE-- 9<?php 10 11ob_start(); 12 13echo "*** Testing session_set_save_handler() function: interface wrong ***\n"; 14 15interface MySessionHandlerInterface { 16 public function open($path, $name); 17 public function close(); 18 public function read($id); 19 public function write($id, $data); 20 public function destroy($id); 21 public function gc($maxlifetime); 22} 23 24class MySession2 implements MySessionHandlerInterface { 25 public $path; 26 27 public function open($path, $name) { 28 if (!$path) { 29 $path = sys_get_temp_dir(); 30 } 31 $this->path = $path . '/u_sess_' . $name; 32 return true; 33 } 34 35 public function close() { 36 return true; 37 } 38 39 public function read($id) { 40 return (string)@file_get_contents($this->path . $id); 41 } 42 43 public function write($id, $data) { 44 echo "Unsupported session handler in use\n"; 45 } 46 47 public function destroy($id) { 48 @unlink($this->path . $id); 49 } 50 51 public function gc($maxlifetime) { 52 foreach (glob($this->path . '*') as $filename) { 53 if (filemtime($filename) + $maxlifetime < time()) { 54 @unlink($filename); 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--EXPECT-- 82*** Testing session_set_save_handler() function: interface wrong *** 83bool(true) 84session_set_save_handler(): Argument #1 ($open) must be of type SessionHandlerInterface, MySession2 given 85good handler writing 86 87Deprecated: Unknown: Session callback must have a return value of type bool, int returned in Unknown on line 0 88