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