1--TEST-- 2session_set_save_handler test 3--EXTENSIONS-- 4session 5--INI-- 6session.use_cookies=0 7session.use_strict_mode=0 8session.cache_limiter= 9session.name=PHPSESSID 10session.serialize_handler=php 11--FILE-- 12<?php 13error_reporting(E_ALL); 14ob_start(); 15 16class handler implements SessionHandlerInterface { 17 public $data = 'baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}'; 18 function open($save_path, $session_name): bool 19 { 20 print "OPEN: $session_name\n"; 21 return true; 22 } 23 function close(): bool 24 { 25 return true; 26 } 27 function read($key): string|false 28 { 29 print "READ: $key\n"; 30 return $GLOBALS["hnd"]->data; 31 } 32 33 function write($key, $val): bool 34 { 35 print "WRITE: $key, $val\n"; 36 $GLOBALS["hnd"]->data = $val; 37 return true; 38 } 39 40 function destroy($key): bool 41 { 42 print "DESTROY: $key\n"; 43 return true; 44 } 45 46 function gc($max_lifetime): int { return 1; } 47} 48 49$hnd = new handler; 50 51class foo { 52 public $bar = "ok"; 53 public $yes; 54 function method() { $this->yes++; } 55} 56 57session_set_save_handler(new handler()); 58 59session_id("test004"); 60session_start(); 61$_SESSION["baz"]->method(); 62$_SESSION["arr"][3]->method(); 63 64var_dump($_SESSION["baz"]); 65var_dump($_SESSION["arr"]); 66 67session_write_close(); 68 69session_set_save_handler(new handler()); 70session_start(); 71 72var_dump($_SESSION["baz"]); 73var_dump($_SESSION["arr"]); 74 75session_destroy(); 76?> 77--EXPECT-- 78OPEN: PHPSESSID 79READ: test004 80object(foo)#3 (2) { 81 ["bar"]=> 82 string(2) "ok" 83 ["yes"]=> 84 int(2) 85} 86array(1) { 87 [3]=> 88 object(foo)#4 (2) { 89 ["bar"]=> 90 string(2) "ok" 91 ["yes"]=> 92 int(2) 93 } 94} 95WRITE: test004, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}} 96OPEN: PHPSESSID 97READ: test004 98object(foo)#4 (2) { 99 ["bar"]=> 100 string(2) "ok" 101 ["yes"]=> 102 int(2) 103} 104array(1) { 105 [3]=> 106 object(foo)#3 (2) { 107 ["bar"]=> 108 string(2) "ok" 109 ["yes"]=> 110 int(2) 111 } 112} 113DESTROY: test004 114