3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A implements ArrayAccess, IteratorAggregate { private $_value = null; public function __construct($value) { $this->setValue($value); } /** {@inheritDoc} */ public function offsetGet($offset) { if (!isset($this->_value[$offset])) { trigger_error('The offset "' . $offset . '" is not defined for this variable', E_USER_NOTICE); return null; } if (!$this->_value[$offset] instanceof self) { $this->_value[$offset] = new self($this->_value[$offset]); } return $this->_value[$offset]; } /** {@inheritDoc} */ public function offsetSet($offset, $value) { if (!$value instanceof self) { $value = new self($value); } $this->_value[$offset] = $value; } /** {@inheritDoc} */ public function offsetExists($offset) { return isset($this->_value[$offset]); } /** {@inheritDoc} */ public function offsetUnset($offset) { unset($this->_value[$offset]); } public function getValue() { return $this->_value; } public function setValue($value) { $this->_value = $value; return $this; } public function getIterator() { if ($this->_value instanceof Traversable) { return new IteratorIterator($this->_value); } if (is_array($this->_value)) { return new ArrayIterator($this->_value); } trigger_error('Variable not iterable', E_USER_WARNING); return new EmptyIterator; } public function __toString() { return (string) $this->getValue(); } } $a = new A(array()); $a['caca'] = 'prout'; $a['pipi'] = 'chouette'; foreach ($a as $k => $v) { var_dump(array($k, (string) $v)); } $a = new A('test'); foreach ($a as $k => $v) { var_dump(array($k, (string) $v)); } $a = new A(new ArrayObject(['variable', 'totally' => 'iterable'])); foreach ($a as $k => $v) { var_dump(($k, (string) $v)); }

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)
5.4.100.0150.04312.01
5.4.90.0140.04312.02
5.4.80.0150.04212.01
5.4.70.0140.04112.01
5.4.60.0130.04312.01
5.4.50.0180.05312.01
5.4.40.0150.04012.00
5.4.30.0160.07111.99
5.4.20.0140.04311.99
5.4.10.0160.04211.99
5.4.00.0160.03911.48
5.3.200.0140.04412.68
5.3.190.0200.05412.68
5.3.180.0150.04512.67
5.3.170.0130.04612.67
5.3.160.0180.04212.67
5.3.150.0180.04212.68
5.3.140.0150.04412.66
5.3.130.0220.05612.66
5.3.120.0160.04512.66
5.3.110.0190.04412.66
5.3.100.0180.04312.13
5.3.90.0230.06712.11
5.3.80.0160.04312.10
5.3.70.0150.07412.10
5.3.60.0160.04212.09
5.3.50.0210.06712.03
5.3.40.0270.06112.04
5.3.30.0150.04112.00
5.3.20.0210.05211.78
5.3.10.0130.04311.74
5.3.00.0140.04311.73

preferences:
141.56 ms | 1394 KiB | 7 Q