1--TEST-- 2Test session_set_save_handler() : manual shutdown 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 ***\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 51echo "done\n"; 52ob_end_flush(); 53?> 54--EXPECTF-- 55*** Testing session_set_save_handler() : manual shutdown *** 56(#1) constructor called 57(#1) finish called %s 58(#1) writing %s = foo|s:3:"bar"; 59(#1) closing %s 60done 61(#1) destructor called 62