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--EXPECTF--
95*** Testing session_set_save_handler() : basic class wrapping existing handler ***
96Open
97Old Create SID
98Read %s
99string(%d) "%s"
100string(5) "files"
101string(4) "user"
102int(3)
103array(0) {
104}
105Write %s
106Close %s
107Open %s
108Validate ID %s
109Read %s
110array(1) {
111  ["foo"]=>
112  string(5) "hello"
113}
114Update Timestamp %s
115Close %s
116int(10)
117