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