xref: /PHP-5.4/ext/session/tests/005.phpt (revision 8deefa87)
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    function open($save_path, $session_name)
18    {
19        print "OPEN: $session_name\n";
20        return true;
21    }
22    function close()
23    {
24		print "CLOSE\n";
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();
60session_decode($hnd->data);
61
62$_SESSION["baz"]->method();
63$_SESSION["arr"][3]->method();
64
65var_dump($_SESSION["baz"]);
66var_dump($_SESSION["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$_SESSION["baz"]->method();
73$_SESSION["arr"][3]->method();
74
75
76$_SESSION["c"] = 123;
77var_dump($_SESSION["baz"]);
78var_dump($_SESSION["arr"]);
79var_dump($_SESSION["c"]);
80
81session_write_close();
82
83session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
84session_start();
85var_dump($_SESSION["baz"]);
86var_dump($_SESSION["arr"]);
87var_dump($_SESSION["c"]);
88
89session_destroy();
90?>
91--EXPECTF--
92OPEN: PHPSESSID
93READ: abtest
94object(foo)#4 (2) {
95  ["bar"]=>
96  string(2) "ok"
97  ["yes"]=>
98  int(2)
99}
100array(1) {
101  [3]=>
102  object(foo)#2 (2) {
103    ["bar"]=>
104    string(2) "ok"
105    ["yes"]=>
106    int(2)
107  }
108}
109WRITE: 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;}}
110CLOSE
111OPEN: PHPSESSID
112READ: abtest
113object(foo)#2 (2) {
114  ["bar"]=>
115  string(2) "ok"
116  ["yes"]=>
117  int(3)
118}
119array(1) {
120  [3]=>
121  object(foo)#4 (2) {
122    ["bar"]=>
123    string(2) "ok"
124    ["yes"]=>
125    int(3)
126  }
127}
128int(123)
129WRITE: 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;
130CLOSE
131OPEN: PHPSESSID
132READ: abtest
133object(foo)#4 (2) {
134  ["bar"]=>
135  string(2) "ok"
136  ["yes"]=>
137  int(3)
138}
139array(1) {
140  [3]=>
141  object(foo)#2 (2) {
142    ["bar"]=>
143    string(2) "ok"
144    ["yes"]=>
145    int(3)
146  }
147}
148int(123)
149DESTROY: abtest
150CLOSE
151
152