3v4l.org

run code in 300+ PHP versions simultaneously
<?php session_start(); $_SESSION['foo'] = 1; class SessionIterator implements \Iterator { /** * @var array list of keys in the map */ private $_keys; /** * @var mixed current key */ private $_key; /** * Constructor. */ public function __construct() { $this->_keys = array_keys($_SESSION ?? []); } /** * Rewinds internal array pointer. * This method is required by the interface [[\Iterator]]. */ #[\ReturnTypeWillChange] public function rewind() { $this->_key = reset($this->_keys); } /** * Returns the key of the current array element. * This method is required by the interface [[\Iterator]]. * @return mixed the key of the current array element */ #[\ReturnTypeWillChange] public function key() { return $this->_key; } /** * Returns the current array element. * This method is required by the interface [[\Iterator]]. * @return mixed the current array element */ #[\ReturnTypeWillChange] public function current() { return isset($_SESSION[$this->_key]) ? $_SESSION[$this->_key] : null; } /** * Moves the internal pointer to the next array element. * This method is required by the interface [[\Iterator]]. */ #[\ReturnTypeWillChange] public function next() { do { $this->_key = next($this->_keys); } while (!isset($_SESSION[$this->_key]) && $this->_key !== false); } /** * Returns whether there is an element at current position. * This method is required by the interface [[\Iterator]]. * @return bool */ #[\ReturnTypeWillChange] public function valid() { return $this->_key !== false; } } $si = new SessionIterator(); foreach ($si as $key => $value) { var_dump($key, $value); }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.120.0090.00018.80
8.3.110.0060.00320.94
8.3.100.0060.00318.45
8.3.90.0080.00026.77
8.3.80.0090.00016.88
8.3.70.0090.00616.75
8.3.60.0160.00018.68
8.3.50.0110.00720.08
8.3.40.0110.00821.96
8.3.30.0130.00719.17
8.3.20.0030.00624.18
8.3.10.0090.00024.66
8.3.00.0070.01126.16
8.2.240.0030.00618.45
8.2.230.0060.00322.58
8.2.220.0060.00324.06
8.2.210.0060.00626.77
8.2.200.0060.00318.37
8.2.190.0150.00016.58
8.2.180.0110.01125.92
8.2.170.0000.01918.97
8.2.160.0080.00622.96
8.2.150.0070.00025.66
8.2.140.0070.01024.66
8.2.130.0140.00426.16
8.2.120.0080.00026.16
8.2.110.0000.00820.64
8.2.100.0000.01120.32
8.1.300.0110.00416.09
8.1.290.0070.00330.84
8.1.280.0150.00625.92
8.1.270.0050.00324.02
8.1.260.0000.00726.35
8.1.250.0000.00728.09
8.1.240.0070.00318.64
8.1.230.0090.00018.68
8.1.130.0240.00618.33
8.1.60.0050.00317.65
8.0.190.0040.00616.88

preferences:
41.54 ms | 403 KiB | 5 Q