3v4l.org

run code in 300+ PHP versions simultaneously
<?php // modified from: http://us1.php.net/manual/en/class.arrayaccess.php#99236 // sanity and error checking omitted for brevity // note: it's a good idea to implement arrayaccess + countable + // an iterator interface (like iteratoraggregate) as a triplet /* // WORKS. class Template implements ArrayAccess { // makes it so we can do $template_inst['foo']; public $config = array(); // necessary for deep copies public function __clone() { foreach ($this->config as $key => $value) if ($value instanceof self) $this[$key] = clone $value; } public function __construct(array $config = array()) { foreach ($config as $key => $value) $this[$key] = $value; } public function offsetSet($offset, $config) { if (is_array($config)) { $config = new self($config); } if ($offset === null) { // don't forget this! $this->config[] = $config; } else { $this->config[$offset] = $config; } } public function toArray() { $config = $this->config; foreach ($config as $key => $value) if ($value instanceof self) $config[$key] = $value->toArray(); return $config; } // as normal public function offsetGet($offset) { return $this->config[$offset]; } public function offsetExists($offset) { return isset($this->config[$offset]); } public function offsetUnset($offset) { unset($this->config); } } */ // DOESN'T WORK class Template implements ArrayAccess { // makes it so we can do $template_inst['foo']; // container for items passed with null $offset: $this[] = $value; public $implied_key_list = array(); // necessary for deep copies public function __clone() { foreach ($this as $key => $value) if ($value instanceof self) $this[$key] = clone $value; } public function __construct(array $items = array()) { foreach ($items as $key => $value) { $this[$key] = $value; } } public function offsetSet($offset, $value) { if (is_array($value)) { $value = new self(array($offset => $value)); } # segfault from this line if ($offset === null) { // don't forget this! allows `$this[] = $value;` $this->implied_key_list[] = $value; } else { $this->$offset = $value; } } // as normal public function offsetGet($offset) { return $this->$offset; } public function offsetExists($offset) { return isset($this->$offset); } public function offsetUnset($offset) { unset($this->$offset); } } $test = new Template(array('noises' => array('dog' => 'woof'))); echo "<pre><code>"; print_r($test); echo "</code></pre>";

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.60.0390.02751.63
8.3.50.0580.02551.63
8.3.40.0430.00748.26
8.3.30.0430.01048.68
8.3.20.0180.01149.66
8.3.10.0190.00451.35
8.3.00.0260.00348.41
8.2.180.0260.01035.25
8.2.170.0420.00737.68
8.2.160.0220.01339.14
8.2.150.0170.00337.77
8.2.140.0140.00737.87
8.2.130.0090.00640.07
8.2.120.0140.00038.79
8.2.110.0120.00640.12
8.2.100.0200.00736.52
8.2.90.0130.00337.96
8.2.80.0140.00336.38
8.2.70.0120.00936.50
8.2.60.0180.00636.68
8.2.50.0130.00336.50
8.2.40.0100.00739.04
8.2.30.0120.00637.17
8.2.20.0170.00336.50
8.2.10.0100.00736.93
8.2.00.0120.00936.42
8.1.280.0190.00935.71
8.1.270.0100.00741.97
8.1.260.0140.00336.63
8.1.250.0210.00039.94
8.1.240.0180.00439.85
8.1.230.0280.00036.73
8.1.220.0100.00735.54
8.1.210.0100.00735.11
8.1.200.0140.00435.10
8.1.190.0100.00735.10
8.1.180.0160.00335.10
8.1.170.0160.00336.21
8.1.160.0100.00639.79
8.1.150.0130.00336.41
8.1.140.0130.00335.42
8.1.130.0060.00935.61
8.1.120.0030.01335.37
8.1.110.0130.00735.33
8.1.100.0060.00935.21
8.1.90.0040.01135.23
8.1.80.0060.00935.32
8.1.70.0100.00735.30
8.1.60.0130.00635.45
8.1.50.0160.00035.42
8.1.40.0110.01135.38
8.1.30.0040.01135.49
8.1.20.0070.01035.55
8.1.10.0160.00335.31
8.1.00.0100.00735.17
8.0.300.0100.00734.10
8.0.290.0100.00734.03
8.0.280.0090.00635.25
8.0.270.0160.00734.06
8.0.260.0100.00334.05
8.0.250.0110.00433.70
8.0.240.0130.00033.69
8.0.230.0090.00633.73
8.0.220.0070.00733.58
8.0.210.0100.00333.57
8.0.200.0100.00733.75
8.0.190.0070.01133.79
8.0.180.0160.00033.71
8.0.170.0130.00333.71
8.0.160.0070.00733.70
8.0.150.0140.00433.52
8.0.140.0040.01133.66
8.0.130.0130.00330.18
8.0.120.0120.00433.71
8.0.110.0090.00633.61
8.0.100.0110.00433.52
8.0.90.0090.00633.62
8.0.80.0140.02033.65
8.0.70.0150.00033.66
8.0.60.0150.00033.66
8.0.50.0110.00433.51
8.0.30.0270.01633.94
8.0.20.0340.01833.88
8.0.10.0040.01133.68
8.0.00.0200.02633.76
7.4.330.0070.00731.02
7.4.320.0140.00034.00
7.4.300.0160.00634.13
7.4.290.0070.01034.11
7.4.280.0100.01034.08
7.4.270.0100.00733.86
7.4.260.0210.00334.11
7.4.250.0100.00734.05
7.4.240.0050.01033.99
7.4.230.0090.00634.07
7.4.220.0260.01934.00
7.4.210.0150.02434.03
7.4.200.0160.00033.82
7.4.190.0090.00633.92
7.4.160.0230.01634.05
7.4.150.0200.02334.01
7.4.140.0310.01633.97
7.4.130.0210.01934.03
7.4.120.0230.01833.93
7.4.110.0280.01534.13
7.4.100.0380.01634.00
7.4.90.0250.02534.03
7.4.80.0380.02033.91
7.4.70.0340.01234.13
7.4.60.0360.00634.11
7.4.50.0040.00733.92
7.4.40.0210.01933.89
7.4.30.0280.01134.20
7.4.00.0180.01232.36
7.3.330.0100.00330.99
7.3.320.0100.00331.01
7.3.310.0100.00733.94
7.3.300.0140.00034.03
7.3.290.0530.03034.11
7.3.280.0280.01934.11
7.3.270.0270.01734.11
7.3.260.0180.02534.00
7.3.250.0310.01334.19
7.3.240.0360.01634.15
7.3.230.0460.00633.96
7.3.210.0310.01834.36
7.3.200.0230.01634.34
7.3.190.0320.01334.09
7.3.180.0320.01034.22
7.3.170.0150.02434.08
7.3.160.0390.02334.04
7.3.120.0160.01632.54
7.3.10.0400.00634.55
7.3.00.0230.01634.78
7.2.330.0310.01033.77
7.2.320.0260.02933.91
7.2.310.0200.02433.59
7.2.300.0240.01733.68
7.2.290.0410.01233.91
7.2.130.0390.00932.52
7.2.120.0240.00732.85
7.2.110.0280.01232.96
7.2.100.0260.00932.73
7.2.90.0330.00732.86
7.2.80.0250.01832.79
7.2.70.0360.00732.84
7.2.60.0260.01432.87
7.2.50.0390.00633.00
7.2.40.0280.01432.71
7.2.30.0210.00832.86
7.2.20.0350.00632.92
7.2.10.0360.01332.86
7.2.00.0170.01234.04
7.1.250.0390.01133.59
7.1.100.0090.00636.15
7.1.70.0130.01634.81
7.1.60.0140.01035.48
7.1.50.0390.00635.26
7.1.00.0070.08040.12
7.0.200.0170.00332.88
7.0.140.0070.07340.04
7.0.90.1930.03737.55
7.0.80.1930.07337.57
7.0.70.2330.06737.65
7.0.60.2700.05337.57
7.0.50.2670.08038.18
7.0.40.0130.08028.14
7.0.30.0130.04028.05
7.0.20.0200.08328.07
7.0.10.0170.08028.06
7.0.00.0100.09328.01
5.6.280.0200.08045.94
5.6.230.0100.04745.48
5.6.220.0130.09045.39
5.6.210.0130.09345.45
5.6.200.0170.08745.97
5.6.190.0200.08345.87
5.6.180.0130.09345.87
5.6.170.0200.08745.79
5.6.160.0130.05045.99
5.6.150.0200.09045.90
5.6.140.0230.09345.92
5.6.130.0130.10345.81
5.6.120.0130.08045.86
5.6.110.0300.04745.98
5.6.100.0100.06745.91
5.6.90.0100.09745.79
5.6.80.0230.08345.27
5.6.70.0170.06745.40
5.6.60.0170.07745.21
5.6.50.0170.08745.36
5.6.40.0230.06045.22
5.6.30.0230.08345.11
5.6.20.0230.07345.21
5.6.10.0200.08745.21
5.6.00.0100.08745.25
5.5.370.0130.05046.20
5.5.360.0170.09346.08
5.5.350.0230.09346.21
5.5.340.0130.08746.64
5.5.330.0170.08746.64
5.5.320.0330.08046.53
5.5.310.0100.08046.54
5.5.300.0270.08746.40
5.5.290.0170.09746.68
5.5.280.0130.07346.56
5.5.270.0130.06046.50
5.5.260.0170.09746.56
5.5.250.0100.10046.45
5.5.240.0130.09346.04
5.5.230.0170.06746.00
5.5.220.0170.08346.03
5.5.210.0270.08046.00
5.5.200.0370.04746.01
5.5.190.0200.05345.98
5.5.180.0230.04345.93
5.5.160.0170.06345.99
5.5.150.0130.09345.73
5.5.140.0270.08045.98
5.5.130.0170.08046.00
5.5.120.0130.05045.93
5.5.110.0170.07746.02
5.5.100.0130.09345.90
5.5.90.0170.08345.69
5.5.80.0100.09345.90
5.5.70.0130.09045.89
5.5.60.0200.07745.86
5.5.50.0130.05045.83
5.5.40.0130.10045.84
5.5.30.0230.08345.90
5.5.20.0230.08345.78
5.5.10.0170.09045.79
5.5.00.0200.08045.71
5.4.450.0200.09046.07
5.4.440.0270.08046.24
5.4.430.0100.10046.24
5.4.420.0170.09346.25
5.4.410.0200.08045.95
5.4.400.0070.10345.80
5.4.390.0300.07745.55
5.4.380.0170.09045.75
5.4.370.0200.08745.92
5.4.360.0200.04745.81
5.4.350.0170.09745.75
5.4.340.0200.09045.93
5.4.320.0200.07345.57
5.4.310.0200.08745.73
5.4.300.0070.09745.54
5.4.290.0200.04345.74
5.4.280.0330.07045.61
5.4.270.0200.09345.73
5.4.260.0170.09045.87
5.4.250.0100.07045.66
5.4.240.0200.05345.74
5.4.230.0330.07345.72
5.4.220.0130.06745.75
5.4.210.0230.08745.92
5.4.200.0030.08045.66
5.4.190.0200.07745.72
5.4.180.0230.08745.80
5.4.170.0170.09045.72
5.4.160.0270.08045.74
5.4.150.0200.09045.84
5.4.140.0130.09342.65
5.4.130.0270.07342.68
5.4.120.0370.07042.79
5.4.110.0270.07743.10
5.4.100.0200.04043.08
5.4.90.0130.05743.27
5.4.80.0200.07043.24
5.4.70.0100.04743.18
5.4.60.0230.08043.05
5.4.50.0100.05743.15
5.4.40.0200.07343.02
5.4.30.0130.09343.19
5.4.20.0130.04343.05
5.4.10.0130.04043.16
5.4.00.0170.08042.18
5.3.290.0270.05043.35
5.3.280.0200.08742.86
5.3.270.0130.06042.96
5.3.260.0200.09342.87
5.3.250.0200.07742.87
5.3.240.0300.08042.94
5.3.230.0200.09742.81
5.3.220.0170.09041.93
5.3.210.0130.10341.79
5.3.200.0200.08741.86
5.3.190.0170.06041.89
5.3.180.0170.08041.91
5.3.170.0100.09041.96
5.3.160.0070.07341.74
5.3.150.0070.06041.79
5.3.140.0230.07741.74
5.3.130.0070.06741.85
5.3.120.0100.06341.93
5.3.110.0170.04041.79
5.3.100.0230.08341.41
5.3.90.0330.04739.80
5.3.80.0170.09039.23
5.3.70.0230.07739.23
5.3.60.0170.07741.29
5.3.50.0170.08341.11
5.3.40.0230.07741.11
5.3.30.0100.08041.09
5.3.20.0200.08340.89
5.3.10.0100.05741.23
5.3.00.0130.04341.80
5.2.170.0200.06326.16
5.2.160.0100.07326.19
5.2.150.0100.07326.35
5.2.140.0100.06326.29
5.2.130.0170.04026.14
5.2.120.0100.04326.20
5.2.110.0030.03726.32
5.2.100.0130.07026.10
5.2.90.0170.07026.27
5.2.80.0070.07326.21
5.2.70.0100.07026.24
5.2.60.0130.07026.25
5.2.50.0130.07026.08
5.2.40.0100.04326.13
5.2.30.0100.06725.04
5.2.20.0070.05725.00
5.2.10.0100.07025.16
5.2.00.0200.05725.93
5.1.60.0200.05726.96
5.1.50.0200.05726.96
5.1.40.0130.05726.98
5.1.30.0170.05327.33
5.1.20.0170.06327.33
5.1.10.0070.05026.77
5.1.00.0100.06726.98
5.0.50.0030.04313.57
5.0.40.0030.04313.57
5.0.30.0070.04013.57
5.0.20.0030.04013.57
5.0.10.0030.04313.57
5.0.00.0030.06313.57
4.4.90.0030.03013.57
4.4.80.0030.03313.57
4.4.70.0100.02313.57
4.4.60.0100.02713.57
4.4.50.0030.02713.57
4.4.40.0000.05313.57
4.4.30.0000.03713.57
4.4.20.0030.03313.57
4.4.10.0000.03713.57
4.4.00.0000.05313.57
4.3.110.0030.02313.57
4.3.100.0000.02013.57
4.3.90.0000.02713.57
4.3.80.0070.05013.57
4.3.70.0030.03313.57
4.3.60.0100.02713.57
4.3.50.0030.03313.57
4.3.40.0000.05713.57
4.3.30.0000.02713.57
4.3.20.0000.03013.57
4.3.10.0000.02713.57
4.3.00.0000.03713.57

preferences:
48.78 ms | 401 KiB | 5 Q