1--TEST--
2Test session_set_save_handler() function: interface wrong
3--INI--
4session.save_handler=files
5session.name=PHPSESSID
6--EXTENSIONS--
7session
8--SKIPIF--
9<?php include('skipif.inc'); ?>
10--FILE--
11<?php
12
13ob_start();
14
15echo "*** Testing session_set_save_handler() function: interface wrong ***\n";
16
17interface MySessionHandlerInterface {
18    public function open($path, $name): bool;
19    public function close(): bool;
20    public function read($id): string|false;
21    public function write($id, $data): bool;
22    public function destroy($id): bool;
23    public function gc($maxlifetime): int|false;
24}
25
26class MySession2 implements MySessionHandlerInterface {
27    public $path;
28
29    public function open($path, $name): bool {
30        if (!$path) {
31            $path = sys_get_temp_dir();
32        }
33        $this->path = $path . '/u_sess_' . $name;
34        return true;
35    }
36
37    public function close(): bool {
38        return true;
39    }
40
41    public function read($id): string|false {
42        return (string)@file_get_contents($this->path . $id);
43    }
44
45    public function write($id, $data): bool {
46        echo "Unsupported session handler in use\n";
47        return false;
48    }
49
50    public function destroy($id): bool {
51        @unlink($this->path . $id);
52        return true;
53    }
54
55    public function gc($maxlifetime): int|false {
56        foreach (glob($this->path . '*') as $filename) {
57            if (filemtime($filename) + $maxlifetime < time()) {
58                @unlink($filename);
59            }
60        }
61
62        return true;
63    }
64}
65
66function good_write($id, $data) {
67    global $handler;
68    echo "good handler writing\n";
69    return file_put_contents($handler->path . $id, $data);
70}
71
72$handler = new MySession2;
73
74$ret = session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
75    array($handler, 'read'), 'good_write', array($handler, 'destroy'), array($handler, 'gc'));
76
77var_dump($ret);
78try {
79    $ret = session_set_save_handler($handler);
80} catch (TypeError $e) {
81    echo $e->getMessage(), "\n";
82}
83
84session_start();
85?>
86--EXPECT--
87*** Testing session_set_save_handler() function: interface wrong ***
88bool(true)
89session_set_save_handler(): Argument #1 ($open) must be of type SessionHandlerInterface, MySession2 given
90good handler writing
91
92Deprecated: PHP Request Shutdown: Session callback must have a return value of type bool, int returned in Unknown on line 0
93