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