3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SessionSaveHandler { /** * Constructs the object */ public function __construct() { /** * Register the functions */ session_set_save_handler( array($this, "open"), array($this, "close"), array($this, "read"), array($this, "write"), array($this, "destroy"), array($this, "gc") ); /** * To call the write process before the object cache is destroyed */ register_shutdown_function('session_write_close'); } /** * Opens a connection - Not in use * * @param string $savePath * @param string $sessionName * @return boolean */ public function open($savePath, $sessionName) { return true; } /** * Closing the connection - Not in use * * @return boolean */ public function close() { return true; } /** * Returns the datas for the given session id * * @global WP_Object_Cache $wp_object_cache * @param string $id * @return mixed */ public function read($id) { global $memcachedConnection; return $memcachedConnection->get($this->prepareId($id)); } /** * Saves the datas for the given session id * * @global WP_Object_Cache $wp_object_cache * @param string $id * @param mixed $data */ public function write($id, $data) { global $memcachedConnection; $memcachedConnection->set($this->prepareId($id), $data, 3600); return true; } /** * Deletes the data for the given session id * * @global WP_Object_Cache $wp_object_cache * @param string $id */ public function destroy($id) { global $memcachedConnection; $memcachedConnection->delete($this->prepareId($id)); return true; } /** * Garbage collection - not in use - we have no garbage! * * @param integer $maxlifetime * @return boolean */ public function gc($maxlifetime) { return true; } /** * Returns the id with a prefix * * @param string $id * @return string */ protected function prepareId($id) { return 'SMK_' . md5($_SERVER['SERVER_NAME']) . '_SESSION_' . $id; } } /** * Creates the object and register the new session handler */ $sessionHandler = new SessionSaveHandler();
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/PXc7q on line 8
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
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/PXc7q on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/PXc7q on line 8
Process exited with code 255.

preferences:
263.24 ms | 401 KiB | 459 Q