blob: 7344ae1ef30b2778f17ffb701df249c29866f235 (
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
|
--TEST--
Test session_set_save_handler() : manual shutdown, reopen
--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() : manual shutdown, reopen ***\n";
class MySession extends SessionHandler {
public $num;
public function __construct($num) {
$this->num = $num;
echo "(#$this->num) constructor called\n";
}
public function __destruct() {
echo "(#$this->num) destructor called\n";
}
public function finish() {
$id = session_id();
echo "(#$this->num) finish called $id\n";
session_write_close();
}
public function write($id, $data) {
echo "(#$this->num) writing $id = $data\n";
return parent::write($id, $data);
}
public function close() {
$id = session_id();
echo "(#$this->num) closing $id\n";
return parent::close();
}
}
$handler = new MySession(1);
session_set_save_handler($handler);
session_start();
$_SESSION['foo'] = 'bar';
// explicit close
$handler->finish();
$handler = new MySession(2);
session_set_save_handler($handler);
session_start();
// implicit close (called by shutdown function)
echo "done\n";
ob_end_flush();
?>
--EXPECTF--
*** Testing session_set_save_handler() : manual shutdown, reopen ***
(#1) constructor called
(#1) finish called %s
(#1) writing %s = foo|s:3:"bar";
(#1) closing %s
(#2) constructor called
(#1) destructor called
done
(#2) writing %s = foo|s:3:"bar";
(#2) closing %s
(#2) destructor called
|