3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Session { private $started = false; public function start() { if ($this->started) { return; } session_start(); $this->started = true; } } class AutostartingSessionBag implements ArrayAccess { private $session; public function __construct(Session $session) { $this->session = $session; } public function offsetExists($offset) { $this->ensureSessionStarted(); return isset($_SESSION[$offset]); } public function offsetGet($offset) { $this->ensureSessionStarted(); return $_SESSION[$offset]; } public function offsetSet($offset, $vaue) { $this->ensureSessionStarted(); $_SESSION[$offset] = $value; } public function offsetUnset($offset) { $this->ensureSessionStarted(); unset($_SESSION[$offset]); } private function ensureSessionStarted() { $this->session->start(); } } //var_dump($_SESSION); $_SESSION = new AutostartingSessionBag(new Session()); //var_dump($_SESSION); $_SESSION['test'] = 'foobar'; var_dump($_SESSION);
based on HTfNE
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.21.3, 7.0.0 - 7.2.6
Notice: Undefined variable: value in /in/83irp on line 41 array(1) { ["test"]=> NULL }
Output for hhvm-3.22.0
Notice: Undefined variable: value in /in/83irp on line -1 array(1) { ["test"]=> NULL }