1--TEST-- 2Test session_set_save_handler() : basic class wrapping existing handler 3--INI-- 4session.use_strict_mode=1 5session.name=PHPSESSID 6session.save_handler=files 7--EXTENSIONS-- 8session 9--FILE-- 10<?php 11 12ob_start(); 13 14echo "*** Testing session_set_save_handler() : basic class wrapping existing handler ***\n"; 15 16class MySession extends SessionHandler { 17 public $i = 0; 18 public function open($path, $name): bool { 19 ++$this->i; 20 echo 'Open:', session_id(), "\n"; 21 return parent::open($path, $name); 22 } 23 public function create_sid(): string { 24 // This method should be removed when 5.5 become unsupported. 25 ++$this->i; 26 echo 'Old Create SID:', session_id(), "\n"; 27 return parent::create_sid(); 28 } 29 public function read($key): string|false { 30 ++$this->i; 31 echo 'Read:', session_id(), "\n"; 32 return parent::read($key); 33 } 34 public function write($key, $data): bool { 35 ++$this->i; 36 echo 'Write:', session_id(), "\n"; 37 return parent::write($key, $data); 38 } 39 public function close(): bool { 40 ++$this->i; 41 echo 'Close:', session_id(), "\n"; 42 return parent::close(); 43 } 44 45 public function createSid(): string { 46 // User should use this rather than create_sid() 47 // If both create_sid() and createSid() exists, 48 // createSid() is used. 49 ++$this->i; 50 echo 'New Create ID:', session_id(), "\n"; 51 return parent::create_sid(); 52 } 53 public function validateId($key): bool { 54 ++$this->i; 55 echo 'Validate ID:', session_id(), "\n"; 56 return TRUE; 57 // User must implement their own method and 58 // cannot call parent as follows. 59 // return parent::validateSid($key); 60 } 61 public function updateTimestamp($key, $data): bool { 62 ++$this->i; 63 echo 'Update Timestamp:', session_id(), "\n"; 64 return parent::write($key, $data); 65 // User must implement their own method and 66 // cannot call parent as follows 67 // return parent::updateTimestamp($key, $data); 68 } 69} 70 71$oldHandler = ini_get('session.save_handler'); 72$handler = new MySession; 73session_set_save_handler($handler); 74session_start(); 75 76var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i, $_SESSION); 77 78$_SESSION['foo'] = "hello"; 79 80session_write_close(); 81session_unset(); 82 83session_start(); 84var_dump($_SESSION); 85 86session_write_close(); 87session_unset(); 88var_dump($handler->i); 89?> 90--EXPECTF-- 91*** Testing session_set_save_handler() : basic class wrapping existing handler *** 92Open: 93Old Create SID: 94Read:%s 95string(%d) "%s" 96string(5) "files" 97string(4) "user" 98int(3) 99array(0) { 100} 101Write:%s 102Close:%s 103Open:%s 104Validate ID:%s 105Read:%s 106array(1) { 107 ["foo"]=> 108 string(5) "hello" 109} 110Update Timestamp:%s 111Close:%s 112int(10) 113