3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MySessionHandler implements \SessionHandlerInterface { public $messages = array(); public function open($savePath, $sessionName) { $this->messages[] = 'open ' . $sessionName; } public function close() { $this->messages[] = 'close'; } public function read($id) { $this->messages[] = 'read ' . $id; } public function write($id, $data) { $this->messages[] = 'write ' . $id . ': ' . $data; throw new \RuntimeException('bad'); } public function destroy($id) { $this->messages[] = 'destroy ' . $id; } public function gc($maxlifetime) { $this->messages[] = 'gc ' . var_export($maxlifetime, true); } public function __destruct() { var_dump($this->messages); } } $handler = new MySessionHandler(); session_set_save_handler($handler, true); $handler->messages[] = 'isset($_SESSION): ' . var_export(isset($_SESSION), true); $_SESSION['before'] = 'start'; session_start(); $_SESSION['foo'] = 'bar'; $handler->messages[] = 'current session_id: ' . session_id(); session_regenerate_id(true); $handler->messages[] = 'current session_id: ' . session_id(); try { session_write_close(); } catch (\Exception $e) { } session_start(); session_destroy(); $handler->messages[] = var_export($_SESSION, true); $handler->messages[] = 'current session_id: ' . var_export(session_id(), true); session_id('explicit-session-id'); session_start(); $_SESSION['john'] = 'doe';
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of MySessionHandler::open($savePath, $sessionName) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/eiTN8 on line 8 Deprecated: Return type of MySessionHandler::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/eiTN8 on line 13 Deprecated: Return type of MySessionHandler::read($id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/eiTN8 on line 18 Deprecated: Return type of MySessionHandler::write($id, $data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/eiTN8 on line 23 Deprecated: Return type of MySessionHandler::destroy($id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/eiTN8 on line 29 Deprecated: Return type of MySessionHandler::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/eiTN8 on line 34 Warning: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent in /in/eiTN8 on line 46 Warning: session_start(): Session cannot be started after headers have already been sent in /in/eiTN8 on line 51 Warning: session_regenerate_id(): Session ID cannot be regenerated when there is no active session in /in/eiTN8 on line 56 Warning: session_start(): Session cannot be started after headers have already been sent in /in/eiTN8 on line 63 Warning: session_destroy(): Trying to destroy uninitialized session in /in/eiTN8 on line 64 Warning: session_id(): Session ID cannot be changed after headers have already been sent in /in/eiTN8 on line 69 Warning: session_start(): Session cannot be started after headers have already been sent in /in/eiTN8 on line 70 array(5) { [0]=> string(23) "isset($_SESSION): false" [1]=> string(20) "current session_id: " [2]=> string(20) "current session_id: " [3]=> string(50) "array ( 'before' => 'start', 'foo' => 'bar', )" [4]=> string(22) "current session_id: ''" }
Output for 8.0.0 - 8.0.30
Fatal error: Uncaught TypeError: Session callback must have a return value of type bool, null returned in /in/eiTN8:51 Stack trace: #0 /in/eiTN8(51): session_start() #1 {main} thrown in /in/eiTN8 on line 51 array(2) { [0]=> string(23) "isset($_SESSION): false" [1]=> string(14) "open PHPSESSID" }
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: session_start(): Session callback expects true/false return value in /in/eiTN8 on line 51 Warning: session_start(): Session callback expects true/false return value in /in/eiTN8 on line 51 Warning: session_start(): Failed to initialize storage module: user (path: ) in /in/eiTN8 on line 51 Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in /in/eiTN8 on line 56 Warning: session_start(): Cannot start session when headers already sent in /in/eiTN8 on line 63 Warning: session_destroy(): Trying to destroy uninitialized session in /in/eiTN8 on line 64 Warning: session_id(): Cannot change session id when headers already sent in /in/eiTN8 on line 69 Warning: session_start(): Cannot start session when headers already sent in /in/eiTN8 on line 70 array(7) { [0]=> string(23) "isset($_SESSION): false" [1]=> string(14) "open PHPSESSID" [2]=> string(5) "close" [3]=> string(20) "current session_id: " [4]=> string(20) "current session_id: " [5]=> string(50) "array ( 'before' => 'start', 'foo' => 'bar', )" [6]=> string(22) "current session_id: ''" }
Output for 7.1.0 - 7.1.33
Warning: session_start(): Session callback expects true/false return value in /in/eiTN8 on line 51 Warning: session_start(): Session callback expects true/false return value in /in/eiTN8 on line 51 Fatal error: session_start(): Failed to initialize storage module: user (path: ) in /in/eiTN8 on line 51
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Warning: session_start(): Session callback expects true/false return value in /in/eiTN8 on line 51 Fatal error: session_start(): Failed to initialize storage module: user (path: ) in /in/eiTN8 on line 51 Warning: Unknown: Session callback expects true/false return value in Unknown on line 0
Process exited with code 255.
Output for 5.4.7 - 5.4.45, 5.5.0 - 5.5.35, 5.6.0 - 5.6.28
Fatal error: Uncaught exception 'RuntimeException' with message 'bad' in /in/eiTN8:26 Stack trace: #0 [internal function]: MySessionHandler->write('explicit-sessio...', 'john|s:3:"doe";') #1 [internal function]: session_write_close() #2 {main} thrown in /in/eiTN8 on line 26
Process exited with code 255.
Output for 5.4.0 - 5.4.6
Fatal error: Uncaught exception 'RuntimeException' with message 'bad' in /in/eiTN8:26 Stack trace: #0 [internal function]: MySessionHandler->write('explicit-sessio...', 'john|s:3:"doe";') #1 [internal function]: session_write_close() #2 {main} thrown in /in/eiTN8 on line 26
Output for 5.3.0 - 5.3.29
Fatal error: Interface 'SessionHandlerInterface' not found in /in/eiTN8 on line 5
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/eiTN8 on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/eiTN8 on line 26 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/eiTN8 on line 60 Fatal error: Interface 'SessionHandlerInterface' not found in /in/eiTN8 on line 4
Process exited with code 255.
Output for 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/eiTN8</b> on line <b>4</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/eiTN8</b> on line <b>26</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/eiTN8</b> on line <b>60</b><br /> <br /> <b>Fatal error</b>: Interface 'SessionHandlerInterface' not found in <b>/in/eiTN8</b> on line <b>4</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.0.4
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/eiTN8</b> on line <b>4</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/eiTN8</b> on line <b>26</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/eiTN8</b> on line <b>60</b><br /> <br /> <b>Fatal error</b>: Class 'SessionHandlerInterface' not found in <b>/in/eiTN8</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting '{' in <b>/in/eiTN8</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting '{' in <b>/in/eiTN8</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `'{'' in <b>/in/eiTN8</b> on line <b>4</b><br />
Process exited with code 255.

preferences:
249.64 ms | 401 KiB | 374 Q