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; } 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); } } var_dump(PHP_SESSION_DISABLED); var_dump(PHP_SESSION_NONE ); var_dump(PHP_SESSION_ACTIVE); var_dump(session_status()); $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(); session_write_close(); var_dump($_SESSION); var_dump(constant('SID')); var_dump(session_id()); var_dump(session_status()); session_start(); var_dump(session_status()); session_destroy(); var_dump($_SESSION); $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 git.master, git.master_jit, rfc.property-hooks
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/hQk12 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/hQk12 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/hQk12 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/hQk12 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/hQk12 on line 28 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/hQk12 on line 33 int(0) int(1) int(2) int(1) Warning: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent in /in/hQk12 on line 50 Warning: session_start(): Session cannot be started after headers have already been sent in /in/hQk12 on line 55 Warning: session_regenerate_id(): Session ID cannot be regenerated when there is no active session in /in/hQk12 on line 60 array(2) { ["before"]=> string(5) "start" ["foo"]=> string(3) "bar" } Fatal error: Uncaught Error: Undefined constant "SID" in /in/hQk12:65 Stack trace: #0 /in/hQk12(65): constant('SID') #1 {main} thrown in /in/hQk12 on line 65 array(3) { [0]=> string(23) "isset($_SESSION): false" [1]=> string(20) "current session_id: " [2]=> string(20) "current session_id: " }
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
49.79 ms | 403 KiB | 8 Q