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