3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Stdlib; error_reporting(E_ALL); use ArrayAccess; use Countable; use IteratorAggregate; use Serializable; /** * Custom framework ArrayObject implementation * * Extends version-specific "abstract" implementation. */ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Countable { /** * Properties of the object have their normal functionality * when accessed as list (var_dump, foreach, etc.). */ const STD_PROP_LIST = 1; /** * Entries can be accessed as properties (read and write). */ const ARRAY_AS_PROPS = 2; /** * @var array */ protected $storage; /** * @var int */ protected $flag; /** * @var string */ protected $iteratorClass; /** * @var array */ protected $protectedProperties; /** * Constructor * * @param array $input * @param int $flags * @param string $iteratorClass */ public function __construct($input = array(), $flags = self::STD_PROP_LIST, $iteratorClass = 'ArrayIterator') { $this->setFlags($flags); $this->storage = $input; $this->setIteratorClass($iteratorClass); $this->protectedProperties = array_keys(get_object_vars($this)); } /** * Returns whether the requested key exists * * @param mixed $key * @return bool */ public function __isset($key) { if ($this->flag == self::ARRAY_AS_PROPS) { return $this->offsetExists($key); } if (in_array($key, $this->protectedProperties)) { throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); } return isset($this->$key); } /** * Sets the value at the specified key to value * * @param mixed $key * @param mixed $value * @return void */ public function __set($key, $value) { if ($this->flag == self::ARRAY_AS_PROPS) { return $this->offsetSet($key, $value); } if (in_array($key, $this->protectedProperties)) { throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); } $this->$key = $value; } /** * Unsets the value at the specified key * * @param mixed $key * @return void */ public function __unset($key) { if ($this->flag == self::ARRAY_AS_PROPS) { return $this->offsetUnset($key); } if (in_array($key, $this->protectedProperties)) { throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); } unset($this->$key); } /** * Returns the value at the specified key by reference * * @param mixed $key * @return mixed */ public function &__get($key) { $ret = null; if ($this->flag == self::ARRAY_AS_PROPS) { $ret =& $this->offsetGet($key); return $ret; } if (in_array($key, $this->protectedProperties)) { throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); } return $this->$key; } /** * Appends the value * * @param mixed $value * @return void */ public function append($value) { $this->storage[] = $value; } /** * Sort the entries by value * * @return void */ public function asort() { asort($this->storage); } /** * Get the number of public properties in the ArrayObject * * @return int */ public function count() { return count($this->storage); } /** * Exchange the array for another one. * * @param array|ArrayObject $data * @return array */ public function exchangeArray($data) { if (!is_array($data) && !is_object($data)) { throw new Exception\InvalidArgumentException('Passed variable is not an array or object, using empty array instead'); } if (is_object($data) && ($data instanceof self || $data instanceof \ArrayObject)) { $data = $data->getArrayCopy(); } if (!is_array($data)) { $data = (array) $data; } $storage = $this->storage; $this->storage = $data; return $storage; } /** * Creates a copy of the ArrayObject. * * @return array */ public function getArrayCopy() { return $this->storage; } /** * Gets the behavior flags. * * @return int */ public function getFlags() { return $this->flag; } /** * Create a new iterator from an ArrayObject instance * * @return \Iterator */ public function getIterator() { $class = $this->iteratorClass; return new $class($this->storage); } /** * Gets the iterator classname for the ArrayObject. * * @return string */ public function getIteratorClass() { return $this->iteratorClass; } /** * Sort the entries by key * * @return void */ public function ksort() { ksort($this->storage); } /** * Sort an array using a case insensitive "natural order" algorithm * * @return void */ public function natcasesort() { natcasesort($this->storage); } /** * Sort entries using a "natural order" algorithm * * @return void */ public function natsort() { natsort($this->storage); } /** * Returns whether the requested key exists * * @param mixed $key * @return bool */ public function offsetExists($key) { return isset($this->storage[$key]); } /** * Returns the value at the specified key * * @param mixed $key * @return mixed */ public function &offsetGet($key) { $ret = null; if (!$this->offsetExists($key)) { return $ret; } $ret =& $this->storage[$key]; return $ret; } /** * Sets the value at the specified key to value * * @param mixed $key * @param mixed $value * @return void */ public function offsetSet($key, $value) { $this->storage[$key] = $value; } /** * Unsets the value at the specified key * * @param mixed $key * @return void */ public function offsetUnset($key) { if ($this->offsetExists($key)) { unset($this->storage[$key]); } } /** * Serialize an ArrayObject * * @return string */ public function serialize() { return serialize(get_object_vars($this)); } /** * Sets the behavior flags * * @param int $flags * @return void */ public function setFlags($flags) { $this->flag = $flags; } /** * Sets the iterator classname for the ArrayObject * * @param string $class * @return void */ public function setIteratorClass($class) { if (class_exists($class)) { $this->iteratorClass = $class; return ; } if (strpos($class, '\\') === 0) { $class = '\\' . $class; if (class_exists($class)) { $this->iteratorClass = $class; return ; } } throw new Exception\InvalidArgumentException('The iterator class does not exist'); } /** * Sort the entries with a user-defined comparison function and maintain key association * * @param callable $function * @return void */ public function uasort($function) { if (is_callable($function)) { uasort($this->storage, $function); } } /** * Sort the entries by keys using a user-defined comparison function * * @param callable $function * @return void */ public function uksort($function) { if (is_callable($function)) { uksort($this->storage, $function); } } /** * Unserialize an ArrayObject * * @param string $data * @return void */ public function unserialize($data) { $ar = unserialize($data); $this->setFlags($ar['flag']); $this->exchangeArray($ar['storage']); $this->setIteratorClass($ar['iteratorClass']); foreach ($ar as $k => $v) { switch ($k) { case 'flag': $this->setFlags($v); break; case 'storage': $this->exchangeArray($v); break; case 'iteratorClass': $this->setIteratorClass($v); break; case 'protectedProperties': continue; default: $this->__set($k, $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)
8.3.60.0130.01018.55
8.3.50.0100.00522.01
8.3.40.0120.00318.67
8.3.30.0110.00418.96
8.3.20.0050.00220.29
8.3.10.0030.00521.97
8.3.00.0040.01122.27
8.2.180.0060.00918.56
8.2.170.0070.01122.96
8.2.160.0040.01119.13
8.2.150.0000.00824.18
8.2.140.0000.00924.66
8.2.130.0110.00426.16
8.2.120.0100.00719.36
8.2.110.0060.00322.28
8.2.100.0000.01119.64
8.2.90.0000.00919.17
8.2.80.0060.00317.97
8.2.70.0060.00317.50
8.2.60.0000.00818.05
8.2.50.0080.00018.07
8.2.40.0080.00019.82
8.2.30.0070.00018.16
8.2.20.0000.00917.60
8.2.10.0080.00017.62
8.2.00.0000.00817.71
8.1.280.0140.00325.92
8.1.270.0080.00022.23
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00623.92
8.1.230.0070.00419.22
8.1.220.0000.00917.74
8.1.210.0030.00518.77
8.1.200.0050.00517.48
8.1.190.0040.00417.61
8.1.180.0040.00418.73
8.1.170.0080.00018.46
8.1.160.0050.00222.11
8.1.150.0000.00818.73
8.1.140.0040.00417.39
8.1.130.0040.00417.86
8.1.120.0000.00717.53
8.1.110.0040.00417.52
8.1.100.0050.00217.49
8.1.90.0040.00417.48
8.1.80.0000.00717.46
8.1.70.0030.00317.43
8.1.60.0000.00817.50
8.1.50.0050.00317.38
8.1.40.0040.00417.56
8.1.30.0080.00017.55
8.1.20.0000.00817.68
8.1.10.0040.00417.50
8.1.00.0040.00417.25
8.0.300.0000.00718.77
8.0.290.0000.00717.05
8.0.280.0000.00818.40
8.0.270.0000.00717.21
8.0.260.0030.00316.92
8.0.250.0000.00817.06
8.0.240.0040.00417.11
8.0.230.0000.00717.01
8.0.220.0000.00717.02
8.0.210.0000.00716.95
8.0.200.0030.00316.95
8.0.190.0090.00017.03
8.0.180.0080.00017.00
8.0.170.0040.00417.02
8.0.160.0030.00617.03
8.0.150.0000.00816.96
8.0.140.0000.00816.96
8.0.130.0030.00313.39
8.0.120.0080.00016.96
8.0.110.0040.00417.00
8.0.100.0100.00016.84
8.0.90.0080.00016.79
8.0.80.0150.00316.92
8.0.70.0000.00816.99
8.0.60.0000.00716.79
8.0.50.0000.00816.79
8.0.30.0090.01117.09
8.0.20.0120.00817.40
8.0.10.0080.00017.14
8.0.00.0100.00916.80
7.4.330.0000.00615.00
7.4.320.0070.00016.64
7.4.300.0000.00616.59
7.4.290.0000.00716.53
7.4.280.0040.00416.63
7.4.270.0030.00316.53
7.4.260.0030.00616.54
7.4.250.0040.00416.45
7.4.240.0040.00316.59
7.4.230.0070.00016.73
7.4.220.0030.02216.67
7.4.210.0100.00916.60
7.4.200.0000.00716.66
7.4.190.0040.00416.66
7.4.160.0080.00816.49
7.4.150.0140.00417.40
7.4.140.0140.00517.86
7.4.130.0090.01016.51
7.4.120.0150.00516.66
7.4.110.0120.00616.63
7.4.100.0070.01116.50
7.4.90.0100.01316.39
7.4.80.0070.01119.39
7.4.70.0120.01216.70
7.4.60.0120.00616.63
7.4.50.0080.00016.54
7.4.40.0060.01022.77
7.4.30.0110.00616.64
7.4.00.0030.00715.20
7.3.330.0000.00613.21
7.3.320.0000.00513.25
7.3.310.0000.00716.20
7.3.300.0030.00316.30
7.3.290.0100.01016.36
7.3.280.0110.00716.34
7.3.270.0130.00317.40
7.3.260.0130.00616.40
7.3.250.0110.00816.51
7.3.240.0120.00916.41
7.3.230.0120.00616.66
7.3.210.0080.01116.41
7.3.200.0070.01119.39
7.3.190.0140.00716.37
7.3.180.0170.00016.63
7.3.170.0060.01416.48
7.3.160.0160.00316.48
7.3.120.0120.00614.79
7.3.10.0070.00716.29
7.3.00.0000.01516.61
7.2.330.0090.01016.77
7.2.320.0170.00716.39
7.2.310.0040.01416.56
7.2.300.0070.01016.67
7.2.290.0110.00516.66
7.2.130.0040.01016.64
7.2.120.0060.00916.81
7.2.110.0050.00516.53
7.2.100.0120.00316.43
7.2.90.0070.01016.54
7.2.80.0050.00516.66
7.2.70.0030.01316.56
7.2.60.0000.01416.84
7.2.50.0110.00316.88
7.2.40.0030.00616.83
7.2.30.0070.00316.71
7.2.20.0040.00816.68
7.2.10.0090.00616.99
7.2.00.0070.01016.76
7.1.250.0070.00715.51
7.1.240.0040.01115.39
7.1.230.0030.01015.39
7.1.220.0060.00915.46
7.1.210.0000.00915.56
7.1.200.0000.01415.41
7.1.190.0060.00715.25
7.1.180.0000.01515.77
7.1.170.0040.00715.79
7.1.160.0090.00615.69
7.1.150.0030.01015.56
7.1.140.0060.00615.69
7.1.130.0090.00615.59
7.1.120.0100.00615.66
7.1.110.0080.00815.51
7.1.100.0070.00715.75
7.1.90.0090.00315.69
7.1.80.0060.00315.45
7.1.70.0080.00816.29
7.1.60.0120.01017.69
7.1.50.0060.01116.31
7.1.40.0040.00715.70
7.1.30.0000.01315.76
7.1.20.0000.01015.34
7.1.10.0080.00415.38
7.1.00.0030.04619.14
7.0.330.0030.01315.21
7.0.320.0070.01015.24
7.0.310.0040.00914.79
7.0.300.0070.00715.36
7.0.290.0070.01015.44
7.0.280.0070.01015.24
7.0.270.0090.00614.91
7.0.260.0110.00415.39
7.0.250.0080.00415.43
7.0.240.0070.00715.38
7.0.230.0030.01315.11
7.0.220.0030.01315.12
7.0.210.0030.01015.13
7.0.200.0000.01015.89
7.0.190.0030.01015.09
7.0.180.0060.00615.43
7.0.170.0070.01015.26
7.0.160.0070.00715.40
7.0.150.0040.00815.23
7.0.140.0100.03418.73
7.0.130.0030.01314.99
7.0.120.0070.01015.23
7.0.110.0030.00915.27
7.0.100.0070.02817.72
7.0.90.0030.02417.68
7.0.80.0050.02617.58
7.0.70.0100.02317.72
7.0.60.0030.02717.58
7.0.50.0080.02817.88
7.0.40.0080.04416.70
7.0.30.0070.03016.69
7.0.20.0050.02816.69
7.0.10.0020.04716.70
7.0.00.0060.04016.71
5.6.380.0000.00914.04
5.6.370.0070.00414.23
5.6.360.0030.01014.34
5.6.350.0070.01014.34
5.6.340.0090.00614.04
5.6.330.0000.01113.68
5.6.320.0100.00314.38
5.6.310.0080.00014.21
5.6.300.0100.00713.89
5.6.290.0040.01114.06
5.6.280.0030.04217.70
5.6.270.0040.01114.48
5.6.260.0080.00814.16
5.6.250.0100.02017.35
5.6.240.0050.02517.44
5.6.230.0070.02217.36
5.6.220.0030.02117.36
5.6.210.0020.03117.45
5.6.200.0090.04217.62
5.6.190.0080.04517.73
5.6.180.0050.02417.51
5.6.170.0070.04117.64
5.6.160.0060.03817.72
5.6.150.0050.02317.62
5.6.140.0050.03317.60
5.6.130.0080.04717.79
5.6.120.0140.02817.78
5.6.110.0050.05017.63
5.6.100.0150.04017.62
5.6.90.0030.02917.75
5.6.80.0020.05217.43
5.6.70.0080.02217.40
5.6.60.0070.04217.24
5.6.50.0000.03317.44
5.6.40.0090.04017.24
5.6.30.0070.02217.18
5.6.20.0080.04017.33
5.6.10.0020.04317.33
5.6.00.0090.03917.29
5.5.380.0090.02015.67
5.5.370.0070.02315.87
5.5.360.0000.02315.86
5.5.350.0050.03015.67
5.5.340.0030.04215.97
5.5.330.0050.03715.84
5.5.320.0080.03816.10
5.5.310.0050.05316.04
5.5.300.0060.04515.80
5.5.290.0070.03216.09
5.5.280.0080.04316.08
5.5.270.0050.04415.91
5.5.260.0070.04515.77
5.5.250.0120.04215.78
5.5.240.0060.03115.78
5.5.230.0070.03315.53
5.5.220.0030.03215.72
5.5.210.0090.03715.50
5.5.200.0050.02315.54
5.5.190.0060.04515.57
5.5.180.0030.04115.54
5.5.170.0030.00710.73
5.5.160.0020.04615.50
5.5.150.0080.02715.65
5.5.140.0080.02715.68
5.5.130.0070.02815.45
5.5.120.0050.02215.65
5.5.110.0020.02615.57
5.5.100.0070.02215.52
5.5.90.0030.04715.50
5.5.80.0070.04215.68
5.5.70.0030.04615.47
5.5.60.0090.03515.62
5.5.50.0060.04015.50
5.5.40.0050.02315.49
5.5.30.0050.04215.61
5.5.20.0050.04515.54
5.5.10.0120.03815.34
5.5.00.0040.04015.51
5.4.450.0030.04815.16
5.4.440.0030.04515.29
5.4.430.0110.03914.95
5.4.420.0060.02814.96
5.4.410.0060.02615.02
5.4.400.0080.03715.04
5.4.390.0020.03015.02
5.4.380.0060.02014.89
5.4.370.0050.02115.12
5.4.360.0080.04314.90
5.4.350.0120.03615.06
5.4.340.0020.02214.82
5.4.330.0060.00610.66
5.4.320.0070.03715.12
5.4.310.0070.03814.93
5.4.300.0070.03715.04
5.4.290.0140.03315.05
5.4.280.0080.02314.97
5.4.270.0110.02515.04
5.4.260.0060.04015.01
5.4.250.0030.02814.87
5.4.240.0070.03814.88
5.4.230.0080.02614.88
5.4.220.0080.03814.88
5.4.210.0070.02514.88
5.4.200.0030.02215.13
5.4.190.0070.02715.07
5.4.180.0020.04514.91
5.4.170.0060.02514.89
5.4.160.0050.04114.94
5.4.150.0120.03314.90
5.4.140.0070.03113.76
5.4.130.0070.02813.73
5.4.120.0050.02313.72
5.4.110.0080.04113.75
5.4.100.0080.03813.55
5.4.90.0070.03313.80
5.4.80.0050.03213.79
5.4.70.0090.02613.71
5.4.60.0030.02313.79
5.4.50.0050.04013.73
5.4.40.0070.03913.79
5.4.30.0090.04013.79
5.4.20.0050.02713.61
5.4.10.0050.04113.68
5.4.00.0020.03813.41
5.3.290.0080.03712.69
5.3.280.0030.02512.60
5.3.270.0050.04012.52
5.3.260.0020.05112.72
5.3.250.0050.03512.48
5.3.240.0050.03312.60
5.3.230.0050.04012.69
5.3.220.0080.03312.42
5.3.210.0050.02712.41
5.3.200.0060.04012.50
5.3.190.0080.02612.46
5.3.180.0050.02512.65
5.3.170.0070.04112.61
5.3.160.0010.03912.69
5.3.150.0050.01812.57
5.3.140.0050.03812.47
5.3.130.0000.03812.61
5.3.120.0060.04312.44
5.3.110.0030.03812.62
5.3.100.0100.04212.27
5.3.90.0060.04312.21
5.3.80.0060.03312.21
5.3.70.0000.04812.15
5.3.60.0050.03312.19
5.3.50.0060.04012.23
5.3.40.0050.03912.23
5.3.30.0080.02712.18
5.3.20.0050.03812.07
5.3.10.0050.03811.84
5.3.00.0020.04011.99

preferences:
37.59 ms | 401 KiB | 5 Q