1--TEST--
2Test session_set_save_handler() : manual shutdown, reopen
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(SessionHandler $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() : manual shutdown, reopen ***\n";
20
21class MySession extends SessionHandler {
22	public $num;
23	public function __construct($num) {
24		$this->num = $num;
25		echo "(#$this->num) constructor called\n";
26	}
27	public function __destruct() {
28		echo "(#$this->num) destructor called\n";
29	}
30	public function finish() {
31		$id = session_id();
32		echo "(#$this->num) finish called $id\n";
33		session_write_close();
34	}
35	public function write($id, $data) {
36		echo "(#$this->num) writing $id = $data\n";
37		return parent::write($id, $data);
38	}
39	public function close() {
40		$id = session_id();
41		echo "(#$this->num) closing $id\n";
42		return parent::close();
43	}
44}
45
46$handler = new MySession(1);
47session_set_save_handler($handler);
48session_start();
49
50$_SESSION['foo'] = 'bar';
51
52// explicit close
53$handler->finish();
54
55$handler = new MySession(2);
56session_set_save_handler($handler);
57session_start();
58
59$_SESSION['abc'] = 'xyz';
60// implicit close (called by shutdown function)
61echo "done\n";
62ob_end_flush();
63?>
64--EXPECTF--
65*** Testing session_set_save_handler() : manual shutdown, reopen ***
66(#1) constructor called
67(#1) finish called %s
68(#1) writing %s = foo|s:3:"bar";
69(#1) closing %s
70(#2) constructor called
71(#1) destructor called
72done
73(#2) writing %s = foo|s:3:"bar";abc|s:3:"xyz";
74(#2) closing %s
75(#2) destructor called
76