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