1--TEST-- 2Test session_set_save_handler() : manual shutdown function 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 function ***\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, false); 44register_shutdown_function(array($handler, 'finish')); 45session_start(); 46 47$_SESSION['foo'] = 'bar'; 48 49echo "done\n"; 50ob_end_flush(); 51?> 52--EXPECTF-- 53*** Testing session_set_save_handler() : manual shutdown function *** 54(#1) constructor called 55done 56(#1) finish called %s 57(#1) writing %s = foo|s:3:"bar"; 58(#1) closing %s 59(#1) destructor called 60