3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Session_Database{ public function close(){} } class Session { private Session_Database $db; public function __construct(){ // Instantiate new Database object $this->db = new Session_Database(); // Set handler to overide SESSION session_set_save_handler( [$this, '_open'], [$this, '_close'], [$this, '_read'], [$this, '_write'], [$this, '_destroy'], [$this, '_gc'] ); // Start the session session_start(); } public function _open(string $savePath, string $sessionName): bool {return true;} public function _read(string $sessionId): string {return '';} public function _write(string $sessionId, string $data): bool {return true;} public function _destroy(string $sessionId): bool {return true;} public function _gc(int $lifetime): bool {return true;} public function _close(): bool { echo 'closing session'; // Close the database connection $this->db->close(); return true; } } new Session; session_write_close();
Output for 8.5.0 - 8.5.3
Deprecated: session_set_save_handler(): Providing individual callbacks instead of an object implementing SessionHandlerInterface is deprecated in /in/WfN3S on line 15 Warning: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent (sent from /in/WfN3S on line 15) in /in/WfN3S on line 15 Warning: session_start(): Session cannot be started after headers have already been sent (sent from /in/WfN3S on line 15) in /in/WfN3S on line 25
Output for 8.4.1 - 8.4.18
Deprecated: session_set_save_handler(): Providing individual callbacks instead of an object implementing SessionHandlerInterface is deprecated in /in/WfN3S on line 15 Warning: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent in /in/WfN3S on line 15 Warning: session_start(): Session cannot be started after headers have already been sent in /in/WfN3S on line 25
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30
closing session

preferences:
70.58 ms | 983 KiB | 4 Q