1--TEST--
2Test session_set_save_handler() : basic class wrapping existing handler
3--INI--
4session.use_strict_mode=1
5session.name=PHPSESSID
6session.save_handler=files
7--SKIPIF--
8<?php include('skipif.inc'); ?>
9--FILE--
10<?php
11
12ob_start();
13
14echo "*** Testing session_set_save_handler() : basic class wrapping existing handler ***\n";
15
16class MySession extends SessionHandler {
17    public $i = 0;
18    public function open($path, $name) {
19        ++$this->i;
20        echo 'Open ', session_id(), "\n";
21        return parent::open($path, $name);
22    }
23    public function create_sid() {
24        // This method should be removed when 5.5 become unsupported.
25        ++$this->i;
26        echo 'Old Create SID ', session_id(), "\n";
27        return parent::create_sid();
28    }
29    public function read($key) {
30        ++$this->i;
31        echo 'Read ', session_id(), "\n";
32        return parent::read($key);
33    }
34    public function write($key, $data) {
35        ++$this->i;
36        echo 'Write ', session_id(), "\n";
37        return parent::write($key, $data);
38    }
39    public function close() {
40        ++$this->i;
41        echo 'Close ', session_id(), "\n";
42        return parent::close();
43    }
44    public function createSid() {
45        // User should use this rather than create_sid()
46        // If both create_sid() and createSid() exists,
47        // createSid() is used.
48        ++$this->i;
49        echo 'New Create ID ', session_id(), "\n";
50        return parent::create_sid();
51    }
52    public function validateId($key) {
53        ++$this->i;
54        echo 'Validate ID ', session_id(), "\n";
55        return TRUE;
56        // User must implement their own method and
57        // cannot call parent as follows.
58        // return parent::validateSid($key);
59    }
60    public function updateTimestamp($key, $data) {
61        ++$this->i;
62        echo 'Update Timestamp ', session_id(), "\n";
63        return parent::write($key, $data);
64        // User must implement their own method and
65        // cannot call parent as follows
66        // return parent::updateTimestamp($key, $data);
67    }
68}
69
70$oldHandler = ini_get('session.save_handler');
71$handler = new MySession;
72session_set_save_handler($handler);
73session_start();
74
75var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i, $_SESSION);
76
77$_SESSION['foo'] = "hello";
78
79session_write_close();
80session_unset();
81
82session_start();
83var_dump($_SESSION);
84
85session_write_close();
86session_unset();
87var_dump($handler->i);
88?>
89--EXPECTF--
90*** Testing session_set_save_handler() : basic class wrapping existing handler ***
91Open
92Old Create SID
93Read %s
94string(%d) "%s"
95string(5) "files"
96string(4) "user"
97int(3)
98array(0) {
99}
100Write %s
101Close %s
102Open %s
103Validate ID %s
104Read %s
105array(1) {
106  ["foo"]=>
107  string(5) "hello"
108}
109Update Timestamp %s
110Close %s
111int(10)
112