xref: /PHP-5.3/ext/session/tests/004.phpt (revision 8deefa87)
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
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$baz->method();
60$arr[3]->method();
61
62var_dump($baz);
63var_dump($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($baz);
71var_dump($arr);
72
73session_destroy();
74?>
75--EXPECT--
76Deprecated: Directive 'register_globals' is deprecated in PHP 5.3 and greater in Unknown on line 0
77OPEN: PHPSESSID
78READ: abtest
79object(foo)#2 (2) {
80  ["bar"]=>
81  string(2) "ok"
82  ["yes"]=>
83  int(2)
84}
85array(1) {
86  [3]=>
87  object(foo)#3 (2) {
88    ["bar"]=>
89    string(2) "ok"
90    ["yes"]=>
91    int(2)
92  }
93}
94WRITE: 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;}}
95OPEN: PHPSESSID
96READ: abtest
97object(foo)#4 (2) {
98  ["bar"]=>
99  string(2) "ok"
100  ["yes"]=>
101  int(2)
102}
103array(1) {
104  [3]=>
105  object(foo)#2 (2) {
106    ["bar"]=>
107    string(2) "ok"
108    ["yes"]=>
109    int(2)
110  }
111}
112DESTROY: abtest
113