1--TEST--
2Test session_set_save_handler() function: interface wrong
3--INI--
4session.save_handler=files
5session.name=PHPSESSID
6--SKIPIF--
7<?php include('skipif.inc'); ?>
8--FILE--
9<?php
10
11ob_start();
12
13/*
14 * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true])
15 * Description : Sets user-level session storage functions
16 * Source code : ext/session/session.c
17 */
18
19echo "*** Testing session_set_save_handler() function: interface wrong ***\n";
20
21interface MySessionHandlerInterface {
22	public function open($path, $name);
23	public function close();
24	public function read($id);
25	public function write($id, $data);
26	public function destroy($id);
27	public function gc($maxlifetime);
28}
29
30class MySession2 implements MySessionHandlerInterface {
31	public $path;
32
33	public function open($path, $name) {
34		if (!$path) {
35			$path = sys_get_temp_dir();
36		}
37		$this->path = $path . '/u_sess_' . $name;
38		return true;
39	}
40
41	public function close() {
42		return true;
43	}
44
45	public function read($id) {
46		return (string)@file_get_contents($this->path . $id);
47	}
48
49	public function write($id, $data) {
50		echo "Unsupported session handler in use\n";
51	}
52
53	public function destroy($id) {
54		@unlink($this->path . $id);
55	}
56
57	public function gc($maxlifetime) {
58		foreach (glob($this->path . '*') as $filename) {
59			if (filemtime($filename) + $maxlifetime < time()) {
60				@unlink($filename);
61			}
62		}
63		return true;
64	}
65}
66
67function good_write($id, $data) {
68	global $handler;
69	echo "good handler writing\n";
70	return file_put_contents($handler->path . $id, $data);
71}
72
73$handler = new MySession2;
74
75$ret = session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
76	array($handler, 'read'), 'good_write', array($handler, 'destroy'), array($handler, 'gc'));
77
78var_dump($ret);
79$ret = session_set_save_handler($handler);
80var_dump($ret);
81
82session_start();
83--EXPECTF--
84*** Testing session_set_save_handler() function: interface wrong ***
85bool(true)
86
87Warning: session_set_save_handler() expects parameter 1 to be SessionHandlerInterface, object given in %s
88bool(false)
89good handler writing
90