3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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; } 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); } } echo 'SS'; session_regenerate_id(); die(); $handler = new MySessionHandler(); $handler->messages[] = 'session_status(): ' . session_status(); $handler->messages[] = 'session_id before start: ' . var_export(session_id(), true); 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(); session_write_close(); $handler->messages[] = '$_SESSION after close: ' . var_export($_SESSION, true); $handler->messages[] = 'session_id after close: ' . session_id(); session_start(); session_destroy(); $handler->messages[] = '$_SESSION after destroy: ' . var_export($_SESSION, true); $handler->messages[] = 'current session_id: ' . var_export(session_id(), true); session_id('explicit-session-id'); session_start(); $_SESSION['john'] = 'doe';
based on sMe4W
Output for 7.1.0
SS Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in /in/q2arZ on line 45
Output for 5.4.0 - 7.0.14
SS Warning: session_regenerate_id(): Cannot regenerate session id - headers already sent in /in/q2arZ on line 45
Output for 5.3.0 - 5.3.29
Fatal error: Interface 'SessionHandlerInterface' not found in /in/q2arZ on line 5
Process exited with code 255.
Output for 5.0.5 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/q2arZ on line 4 Fatal error: Interface 'SessionHandlerInterface' not found in /in/q2arZ on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/q2arZ on line 4 Fatal error: Class 'SessionHandlerInterface' not found in /in/q2arZ on line 4
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/q2arZ on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/q2arZ on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/q2arZ on line 4
Process exited with code 255.