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