summaryrefslogtreecommitdiff
path: root/ext/session/tests/session_set_save_handler_class_003.phpt
blob: b6b179913a69247880cc25d8fba328498746473e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--TEST--
Test session_set_save_handler() : inheritance
--INI--
session.save_handler=files
session.name=PHPSESSID
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php

ob_start();

/*
 * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true])
 * Description : Sets user-level session storage functions
 * Source code : ext/session/session.c
 */

echo "*** Testing session_set_save_handler() : inheritance ***\n";

class MySession3 extends SessionHandler {
	public $i = 0;
	public function open($path, $name) {
		++$this->i;
		return parent::open($path, $name);
	}
	public function read($key) {
		++$this->i;
		return parent::read($key);
	}
}

class MySession4 extends MySession3 {
	public function write($id, $data) {
		$this->i = "hai";
		return parent::write($id, $data);
	}
}

$handler = new MySession3;
session_set_save_handler($handler);
session_start();

$_SESSION['foo'] = "hello";

session_write_close();
session_unset();

session_start();

var_dump($_SESSION, $handler->i);

session_write_close();
session_unset();

$handler = new MySession4;
session_set_save_handler($handler);

session_start();

$_SESSION['bar'] = 'hello';
session_write_close();
session_unset();

var_dump(session_id(), $_SESSION, $handler->i);

--EXPECTF--
*** Testing session_set_save_handler() : inheritance ***
array(1) {
  ["foo"]=>
  string(5) "hello"
}
int(4)
string(%d) "%s"
array(2) {
  ["foo"]=>
  string(5) "hello"
  ["bar"]=>
  string(5) "hello"
}
string(3) "hai"