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