xref: /PHP-5.4/ext/session/tests/025.phpt (revision 57e0d2ac)
1--TEST--
2custom save handler, multiple session_start()s, complex data structure 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
12
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		print "CLOSE\n";
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    function __construct()
50    {
51        if (ini_get("unicode.semantics")) {
52            $this->data = str_replace('s:', 'U:', $this->data);
53        }
54    }
55}
56
57$hnd = new handler;
58
59class foo {
60    public $bar = "ok";
61    function method() { $this->yes++; }
62}
63
64session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
65
66session_id("abtest");
67session_start();
68$baz = $_SESSION['baz'];
69$arr = $_SESSION['arr'];
70$baz->method();
71$arr[3]->method();
72
73var_dump($baz);
74var_dump($arr);
75
76session_write_close();
77
78session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
79session_start();
80$baz = $_SESSION['baz'];
81$arr = $_SESSION['arr'];
82
83
84$baz->method();
85$arr[3]->method();
86
87
88$c = 123;
89$_SESSION['c'] = $c;
90var_dump($baz); var_dump($arr); var_dump($c);
91
92session_write_close();
93
94session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
95session_start();
96var_dump($baz); var_dump($arr); var_dump($c);
97
98session_destroy();
99?>
100--EXPECTF--
101OPEN: PHPSESSID
102READ: abtest
103object(foo)#%d (2) {
104  ["bar"]=>
105  string(2) "ok"
106  ["yes"]=>
107  int(2)
108}
109array(1) {
110  [3]=>
111  object(foo)#%d (2) {
112    ["bar"]=>
113    string(2) "ok"
114    ["yes"]=>
115    int(2)
116  }
117}
118WRITE: 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;}}
119CLOSE
120OPEN: PHPSESSID
121READ: abtest
122object(foo)#%d (2) {
123  ["bar"]=>
124  string(2) "ok"
125  ["yes"]=>
126  int(3)
127}
128array(1) {
129  [3]=>
130  object(foo)#%d (2) {
131    ["bar"]=>
132    string(2) "ok"
133    ["yes"]=>
134    int(3)
135  }
136}
137int(123)
138WRITE: abtest, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:3;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:3;}}c|i:123;
139CLOSE
140OPEN: PHPSESSID
141READ: abtest
142object(foo)#%d (2) {
143  ["bar"]=>
144  string(2) "ok"
145  ["yes"]=>
146  int(3)
147}
148array(1) {
149  [3]=>
150  object(foo)#%d (2) {
151    ["bar"]=>
152    string(2) "ok"
153    ["yes"]=>
154    int(3)
155  }
156}
157int(123)
158DESTROY: abtest
159CLOSE
160