1--TEST-- 2session_set_save_handler test 3--SKIPIF-- 4<?php include('skipif.inc'); ?> 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 { 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 19 function open($save_path, $session_name) 20 { 21 print "OPEN: $session_name\n"; 22 return true; 23 } 24 function close() 25 { 26 return true; 27 } 28 function read($key) 29 { 30 print "READ: $key\n"; 31 return $GLOBALS["hnd"]->data; 32 } 33 34 function write($key, $val) 35 { 36 print "WRITE: $key, $val\n"; 37 $GLOBALS["hnd"]->data = $val; 38 return true; 39 } 40 41 function destroy($key) 42 { 43 print "DESTROY: $key\n"; 44 return true; 45 } 46 47 function gc() { return true; } 48} 49 50$hnd = new handler; 51 52class foo { 53 public $bar = "ok"; 54 function method() { $this->yes++; } 55} 56 57session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); 58 59session_id("abtest"); 60session_start(); 61 62$baz = $_SESSION['baz']; 63$arr = $_SESSION['arr']; 64$baz->method(); 65$arr[3]->method(); 66 67var_dump($baz); 68var_dump($arr); 69 70session_write_close(); 71 72session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc")); 73session_start(); 74 75var_dump($baz); 76var_dump($arr); 77 78session_destroy(); 79?> 80--EXPECTF-- 81OPEN: PHPSESSID 82READ: abtest 83object(foo)#%d (2) { 84 ["bar"]=> 85 string(2) "ok" 86 ["yes"]=> 87 int(2) 88} 89array(1) { 90 [3]=> 91 object(foo)#%d (2) { 92 ["bar"]=> 93 string(2) "ok" 94 ["yes"]=> 95 int(2) 96 } 97} 98WRITE: abtest, 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;}} 99OPEN: PHPSESSID 100READ: abtest 101object(foo)#%d (2) { 102 ["bar"]=> 103 string(2) "ok" 104 ["yes"]=> 105 int(2) 106} 107array(1) { 108 [3]=> 109 object(foo)#%d (2) { 110 ["bar"]=> 111 string(2) "ok" 112 ["yes"]=> 113 int(2) 114 } 115} 116DESTROY: abtest 117