summaryrefslogtreecommitdiff
path: root/ext/session/tests/session_set_save_handler_class_011.phpt
blob: 04defe937e49104ee485dcdd885cf8cb1e4eab7f (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
--TEST--
Test session_set_save_handler() : shutdown failure
--INI--
session.save_handler=files
session.name=PHPSESSID
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php

ob_start();

echo "*** Testing session_set_save_handler() : shutdown failure ***\n";

class MySession extends SessionHandler {
    public $num;
    public $destroyed = false;
    public function __construct($num) {
        $this->num = $num;
        echo "(#$this->num) constructor called\n";
    }
    public function __destruct() {
        echo "(#$this->num) destructor called\n";
        $this->destroyed = true;
    }
    public function write($id, $data) {
        if ($this->destroyed) {
            echo "(#$this->num) destroyed, cannot write\n";
        } else {
            echo "(#$this->num) writing $id = $data\n";
        }
        return parent::write($id, $data);
    }
    public function close() {
        $id = session_id();
        if ($this->destroyed) {
            echo "(#$this->num) destroyed, cannot write\n";
        } else {
            echo "(#$this->num) closing $id\n";
        }
        return parent::close();
    }
}

$handler = new MySession(1);
session_set_save_handler($handler, false);
session_start();

$_SESSION['foo'] = 'bar';

echo "done\n";
ob_end_flush();
?>
--EXPECT--
*** Testing session_set_save_handler() : shutdown failure ***
(#1) constructor called
done
(#1) destructor called
(#1) destroyed, cannot write
(#1) destroyed, cannot write