3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class a implements \Iterator, \Countable, \ArrayAccess { private $a; private $b; private $c; private $keys = [ 'a', 'b', 'c' ]; private $pointer; public function __construct($a = null, $b = null, $c = null) { $this->a = $a; $this->b = $b; $this->c = $c; } public function count() { $pointer = 0; foreach ($this as $element) { if ($element) { $pointer++; } } return $pointer; } public function current() { $key = $this->key(); return $this->{$key}; } public function key() { return $this->keys[$this->pointer]; } public function next() { $this->pointer++; } public function valid() { return $this->pointer < count($this->keys); } public function rewind() { $this->pointer = 0; } public function offsetExists($offset) { return isset($this->{$offset}); } public function offsetGet($offset) { return $this->{$offset}; } public function offsetSet($offset, $value) { throw new \BadMethodCallException('Object does not implement set'); } public function offsetUnset($offset) { throw new \BadMethodCallException('Value object does not implement modification via unset'); } } $me = new a(1,2,3); var_dump($me->count()); var_dump($me['c']); foreach ($me as $key => $el) { if ($key === 'b') { $me[$key] = 111; } }
based on eMc5N

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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.2.60.0070.00716.77
7.2.00.0000.01219.53
7.1.200.0100.00315.71
7.1.100.0140.00718.09
7.1.70.0000.01116.80
7.1.60.0040.00720.03
7.1.50.0060.00616.70
7.1.00.0030.07322.48
7.0.200.0080.00416.72
7.0.60.0170.07320.05
7.0.50.0100.07317.85
7.0.40.0070.05020.26
7.0.30.0270.08320.15
7.0.20.0330.05720.33
7.0.10.0070.09320.33
7.0.00.0130.05020.19
5.6.280.0070.06320.79
5.6.210.0000.07020.49
5.6.200.0130.03018.22
5.6.190.0070.08720.43
5.6.180.3970.03720.61
5.6.170.0300.07020.47
5.6.160.0170.07320.34
5.6.150.0100.03718.18
5.6.140.0100.07718.18
5.6.130.0170.04718.13
5.6.120.0070.07021.17
5.6.110.0130.08021.13
5.6.100.0130.07720.98
5.6.90.0130.08021.07
5.6.80.0230.05020.54
5.6.70.4470.04320.36
5.5.350.0000.08020.45
5.5.340.0070.05317.93
5.5.330.0000.06020.21
5.5.320.0270.05320.35
5.5.310.0170.04320.24
5.5.300.0170.04317.98
5.5.290.0000.08718.09
5.5.280.0070.08320.80
5.5.270.0170.05720.86
5.5.260.0170.07720.81
5.5.250.0170.07020.57
5.5.240.0330.04020.21
5.4.450.0070.04319.53
5.4.440.0030.06319.49
5.4.430.0000.04719.45
5.4.420.0000.04019.45
5.4.410.0070.03719.02
5.4.400.0030.04018.87
5.4.390.0030.05318.85
5.4.380.0070.05319.00
5.4.370.0130.07319.19
5.4.360.0170.03318.87
5.4.350.0100.03719.32
5.4.340.0070.04019.04
5.4.320.0170.03319.13
5.4.310.0130.03719.22
5.4.300.0170.03319.16
5.4.290.0130.03718.99
5.4.280.0100.04019.23
5.4.270.0100.04018.99
5.4.260.0100.04019.13
5.4.250.0170.04019.24
5.4.240.0100.04019.18
5.4.230.0130.04019.21
5.4.220.0200.07319.08
5.4.210.0270.06319.22
5.4.200.0170.07018.98
5.4.190.0270.06019.08
5.4.180.0370.06318.94
5.4.170.0270.07019.12
5.4.160.0170.07719.20
5.4.150.0200.05318.96
5.4.140.0170.05016.37
5.4.130.0270.05316.66
5.4.120.0300.06316.67
5.4.110.0170.05716.28
5.4.100.0170.05716.59
5.4.90.0130.06716.21
5.4.80.0100.07716.43
5.3.290.0170.03714.67
5.3.280.0100.04314.59
5.3.270.0370.06314.82
5.3.260.0200.04314.68
5.3.250.0430.05314.60
5.3.240.0300.07014.59
5.3.230.0200.05714.64
5.3.220.0230.06714.46
5.3.210.0170.05014.55
5.3.200.0170.07314.55
5.3.190.0170.08014.55
5.3.180.0170.06714.47