xref: /PHP-7.0/ext/session/tests/025.phpt (revision 25e8fcc8)
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.use_strict_mode=0
8session.cache_limiter=
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
19    function open($save_path, $session_name)
20    {
21        print "OPEN: $session_name\n";
22        return true;
23    }
24    function close()
25    {
26		print "CLOSE\n";
27        return true;
28    }
29    function read($key)
30    {
31        print "READ: $key\n";
32        return $GLOBALS["hnd"]->data;
33    }
34
35    function write($key, $val)
36    {
37        print "WRITE: $key, $val\n";
38        $GLOBALS["hnd"]->data = $val;
39        return true;
40    }
41
42    function destroy($key)
43    {
44        print "DESTROY: $key\n";
45        return true;
46    }
47
48    function gc() { return true; }
49
50    function __construct()
51    {
52        if (ini_get("unicode.semantics")) {
53            $this->data = str_replace('s:', 'U:', $this->data);
54        }
55    }
56}
57
58$hnd = new handler;
59
60class foo {
61    public $bar = "ok";
62    function method() { $this->yes++; }
63}
64
65session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
66
67session_id("abtest");
68session_start();
69$baz = $_SESSION['baz'];
70$arr = $_SESSION['arr'];
71$baz->method();
72$arr[3]->method();
73
74var_dump($baz);
75var_dump($arr);
76
77session_write_close();
78
79session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
80session_start();
81$baz = $_SESSION['baz'];
82$arr = $_SESSION['arr'];
83
84
85$baz->method();
86$arr[3]->method();
87
88
89$c = 123;
90$_SESSION['c'] = $c;
91var_dump($baz); var_dump($arr); var_dump($c);
92
93session_write_close();
94
95session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
96session_start();
97var_dump($baz); var_dump($arr); var_dump($c);
98
99session_destroy();
100?>
101--EXPECTF--
102OPEN: PHPSESSID
103READ: abtest
104object(foo)#%d (2) {
105  ["bar"]=>
106  string(2) "ok"
107  ["yes"]=>
108  int(2)
109}
110array(1) {
111  [3]=>
112  object(foo)#%d (2) {
113    ["bar"]=>
114    string(2) "ok"
115    ["yes"]=>
116    int(2)
117  }
118}
119WRITE: 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;}}
120CLOSE
121OPEN: PHPSESSID
122READ: abtest
123object(foo)#%d (2) {
124  ["bar"]=>
125  string(2) "ok"
126  ["yes"]=>
127  int(3)
128}
129array(1) {
130  [3]=>
131  object(foo)#%d (2) {
132    ["bar"]=>
133    string(2) "ok"
134    ["yes"]=>
135    int(3)
136  }
137}
138int(123)
139WRITE: 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;
140CLOSE
141OPEN: PHPSESSID
142READ: abtest
143object(foo)#%d (2) {
144  ["bar"]=>
145  string(2) "ok"
146  ["yes"]=>
147  int(3)
148}
149array(1) {
150  [3]=>
151  object(foo)#%d (2) {
152    ["bar"]=>
153    string(2) "ok"
154    ["yes"]=>
155    int(3)
156  }
157}
158int(123)
159DESTROY: abtest
160CLOSE
161