xref: /PHP-5.3/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=
8register_globals=1
9session.name=PHPSESSID
10session.serialize_handler=php
11--FILE--
12<?php
13
14error_reporting(E_ALL);
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    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
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$baz->method();
62$arr[3]->method();
63
64var_dump($baz);
65var_dump($arr);
66
67session_write_close();
68
69session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
70session_start();
71$baz->method();
72$arr[3]->method();
73
74
75$c = 123;
76session_register("c");
77var_dump($baz); var_dump($arr); var_dump($c);
78
79session_write_close();
80
81session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
82session_start();
83var_dump($baz); var_dump($arr); var_dump($c);
84
85session_destroy();
86?>
87--EXPECTF--
88Deprecated: Directive 'register_globals' is deprecated in PHP 5.3 and greater in Unknown on line 0
89OPEN: PHPSESSID
90READ: abtest
91object(foo)#2 (2) {
92  ["bar"]=>
93  string(2) "ok"
94  ["yes"]=>
95  int(2)
96}
97array(1) {
98  [3]=>
99  object(foo)#3 (2) {
100    ["bar"]=>
101    string(2) "ok"
102    ["yes"]=>
103    int(2)
104  }
105}
106WRITE: 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;}}
107CLOSE
108OPEN: PHPSESSID
109READ: abtest
110
111Deprecated: Function session_register() is deprecated in %s on line %d
112object(foo)#4 (2) {
113  ["bar"]=>
114  string(2) "ok"
115  ["yes"]=>
116  int(3)
117}
118array(1) {
119  [3]=>
120  object(foo)#2 (2) {
121    ["bar"]=>
122    string(2) "ok"
123    ["yes"]=>
124    int(3)
125  }
126}
127int(123)
128WRITE: 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;
129CLOSE
130OPEN: PHPSESSID
131READ: abtest
132object(foo)#3 (2) {
133  ["bar"]=>
134  string(2) "ok"
135  ["yes"]=>
136  int(3)
137}
138array(1) {
139  [3]=>
140  object(foo)#4 (2) {
141    ["bar"]=>
142    string(2) "ok"
143    ["yes"]=>
144    int(3)
145  }
146}
147int(123)
148DESTROY: abtest
149CLOSE
150
151