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