3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * ParameterBag is a container for key/value pairs. * * @author Fabien Potencier <fabien@symfony.com> * * @api */ class ParameterBag implements \IteratorAggregate, \Countable { /** * Parameter storage. * * @var array */ protected $parameters; /** * Constructor. * * @param array $parameters An array of parameters * * @api */ public function __construct(array $parameters = array()) { $this->parameters = $parameters; } /** * Returns the parameters. * * @return array An array of parameters * * @api */ public function all() { return $this->parameters; } /** * Returns the parameter keys. * * @return array An array of parameter keys * * @api */ public function keys() { return array_keys($this->parameters); } /** * Replaces the current parameters by a new set. * * @param array $parameters An array of parameters * * @api */ public function replace(array $parameters = array()) { $this->parameters = $parameters; } /** * Adds parameters. * * @param array $parameters An array of parameters * * @api */ public function add(array $parameters = array()) { $this->parameters = array_replace($this->parameters, $parameters); } /** * Returns a parameter by name. * * @param string $path The key * @param mixed $default The default value if the parameter key does not exist * @param boolean $deep If true, a path like foo[bar] will find deeper items * * @return mixed * * @throws \InvalidArgumentException * * @api */ public function get($path, $default = null, $deep = false) { if (!$deep || false === $pos = strpos($path, '[')) { return array_key_exists($path, $this->parameters) ? $this->parameters[$path] : $default; } $root = substr($path, 0, $pos); if (!array_key_exists($root, $this->parameters)) { return $default; } $value = $this->parameters[$root]; $currentKey = null; for ($i = $pos, $c = strlen($path); $i < $c; $i++) { $char = $path[$i]; if ('[' === $char) { if (null !== $currentKey) { throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i)); } $currentKey = ''; } elseif (']' === $char) { if (null === $currentKey) { throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i)); } if (!is_array($value) || !array_key_exists($currentKey, $value)) { return $default; } $value = $value[$currentKey]; $currentKey = null; } else { if (null === $currentKey) { throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i)); } $currentKey .= $char; } } if (null !== $currentKey) { throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".')); } return $value; } /** * Sets a parameter by name. * * @param string $key The key * @param mixed $value The value * * @api */ public function set($key, $value) { $this->parameters[$key] = $value; } /** * Returns true if the parameter is defined. * * @param string $key The key * * @return Boolean true if the parameter exists, false otherwise * * @api */ public function has($key) { return array_key_exists($key, $this->parameters); } /** * Removes a parameter. * * @param string $key The key * * @api */ public function remove($key) { unset($this->parameters[$key]); } /** * Returns the alphabetic characters of the parameter value. * * @param string $key The parameter key * @param mixed $default The default value if the parameter key does not exist * @param boolean $deep If true, a path like foo[bar] will find deeper items * * @return string The filtered value * * @api */ public function getAlpha($key, $default = '', $deep = false) { return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep)); } /** * Returns the alphabetic characters and digits of the parameter value. * * @param string $key The parameter key * @param mixed $default The default value if the parameter key does not exist * @param boolean $deep If true, a path like foo[bar] will find deeper items * * @return string The filtered value * * @api */ public function getAlnum($key, $default = '', $deep = false) { return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep)); } /** * Returns the digits of the parameter value. * * @param string $key The parameter key * @param mixed $default The default value if the parameter key does not exist * @param boolean $deep If true, a path like foo[bar] will find deeper items * * @return string The filtered value * * @api */ public function getDigits($key, $default = '', $deep = false) { // we need to remove - and + because they're allowed in the filter return str_replace(array('-', '+'), '', $this->filter($key, $default, $deep, FILTER_SANITIZE_NUMBER_INT)); } /** * Returns the parameter value converted to integer. * * @param string $key The parameter key * @param mixed $default The default value if the parameter key does not exist * @param boolean $deep If true, a path like foo[bar] will find deeper items * * @return integer The filtered value * * @api */ public function getInt($key, $default = 0, $deep = false) { return (int) $this->get($key, $default, $deep); } /** * Filter key. * * @param string $key Key. * @param mixed $default Default = null. * @param boolean $deep Default = false. * @param integer $filter FILTER_* constant. * @param mixed $options Filter options. * * @see http://php.net/manual/en/function.filter-var.php * * @return mixed */ public function filter($key, $default = null, $deep = false, $filter = FILTER_DEFAULT, $options = array()) { $value = $this->get($key, $default, $deep); // Always turn $options into an array - this allows filter_var option shortcuts. if (!is_array($options) && $options) { $options = array('flags' => $options); } // Add a convenience check for arrays. if (is_array($value) && !isset($options['flags'])) { $options['flags'] = FILTER_REQUIRE_ARRAY; } return filter_var($value, $filter, $options); } /** * Returns an iterator for parameters. * * @return \ArrayIterator An \ArrayIterator instance */ public function getIterator() { return new \ArrayIterator($this->parameters); } /** * Returns the number of parameters. * * @return int The number of parameters */ public function count() { return count($this->parameters); } } $test = new ParameterBag(array('test' => 'test%2B12')); echo $test->get('test');

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.0150.00018.61
8.3.50.0150.00321.08
8.3.40.0150.00018.92
8.3.30.0090.00618.81
8.3.20.0040.00418.69
8.3.10.0050.00320.66
8.3.00.0000.00919.41
8.2.180.0150.00616.63
8.2.170.0090.00622.96
8.2.160.0040.01522.23
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0000.00819.89
8.2.110.0060.00320.39
8.2.100.0040.00817.97
8.2.90.0000.00919.21
8.2.80.0000.00917.97
8.2.70.0030.00617.63
8.2.60.0090.00018.05
8.2.50.0060.00318.07
8.2.40.0040.00418.16
8.2.30.0050.00319.91
8.2.20.0080.00017.79
8.2.10.0030.00517.79
8.2.00.0030.00617.87
8.1.280.0130.00325.92
8.1.270.0030.00623.99
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0060.00322.06
8.1.230.0090.00317.64
8.1.220.0060.00317.74
8.1.210.0040.00418.77
8.1.200.0030.00717.48
8.1.190.0000.00917.76
8.1.180.0040.00418.10
8.1.170.0040.00419.02
8.1.160.0040.00418.91
8.1.150.0000.00818.62
8.1.140.0040.00417.41
8.1.130.0000.00717.88
8.1.120.0000.00717.53
8.1.110.0040.00417.53
8.1.100.0080.00017.41
8.1.90.0000.00817.50
8.1.80.0030.00417.50
8.1.70.0030.00317.41
8.1.60.0000.00717.64
8.1.50.0000.00817.52
8.1.40.0000.00717.59
8.1.30.0040.00417.60
8.1.20.0040.00417.69
8.1.10.0000.00917.67
8.1.00.0030.00617.45
8.0.300.0040.00418.77
8.0.290.0030.00616.88
8.0.280.0040.00418.44
8.0.270.0030.00317.38
8.0.260.0000.00716.84
8.0.250.0080.00017.09
8.0.240.0000.00817.05
8.0.230.0000.00716.90
8.0.220.0040.00416.95
8.0.210.0000.00816.83
8.0.200.0000.00817.05
8.0.190.0040.00417.05
8.0.180.0030.00716.98
8.0.170.0050.00516.96
8.0.160.0080.00017.04
8.0.150.0090.00016.82
8.0.140.0000.01016.83
8.0.130.0070.00013.45
8.0.120.0050.00216.82
8.0.110.0030.00517.06
8.0.100.0000.00716.75
8.0.90.0000.00716.81
8.0.80.0030.01216.92
8.0.70.0050.00316.80
8.0.60.0000.00716.85
8.0.50.0080.00016.94
8.0.30.0120.00717.22
8.0.20.0130.00617.40
8.0.10.0040.00417.05
8.0.00.0090.01216.87
7.4.330.0030.00313.43
7.4.320.0000.00616.67
7.4.300.0070.00016.62
7.4.290.0080.00016.55
7.4.280.0040.00416.52
7.4.270.0000.00716.58
7.4.260.0000.00713.23
7.4.250.0030.00616.69
7.4.240.0000.00716.69
7.4.230.0030.00316.54
7.4.220.0060.01216.60
7.4.210.0100.00816.58
7.4.200.0000.00716.64
7.4.190.0000.00716.71
7.4.160.0040.01116.48
7.4.150.0070.01017.40
7.4.140.0090.00817.27
7.4.130.0130.00716.59
7.4.120.0100.00816.61
7.4.110.0100.00716.63
7.4.100.0110.00716.68
7.4.90.0040.01316.62
7.4.80.0140.00319.03
7.4.70.0120.00316.59
7.4.60.0040.01216.52
7.4.50.0090.00016.65
7.4.40.0070.01122.27
7.4.30.0070.01616.53
7.4.10.0080.00316.48
7.4.00.0050.00615.71
7.3.330.0000.00613.28
7.3.320.0000.00613.31
7.3.310.0030.00316.33
7.3.300.0000.00716.32
7.3.290.0050.00816.40
7.3.280.0120.00516.44
7.3.270.0130.00317.40
7.3.260.0130.00818.24
7.3.250.0060.01416.66
7.3.240.0080.01216.37
7.3.230.0030.01316.64
7.3.210.0100.00716.61
7.3.200.0100.00719.39
7.3.190.0110.01116.32
7.3.180.0070.01416.54
7.3.170.0080.00816.38
7.3.160.0100.01316.53
7.3.130.0100.01016.29
7.3.120.0120.00415.74
7.3.110.0040.01116.55
7.3.100.0070.01016.57
7.3.90.0070.01016.59
7.3.80.0030.01016.41
7.3.70.0110.00016.40
7.3.60.0130.00816.40
7.3.50.0110.00616.22
7.3.40.0070.01316.38
7.3.30.0080.00316.45
7.3.20.0080.00818.07
7.3.10.0110.00718.14
7.3.00.0090.00918.06
7.2.330.0090.00916.64
7.2.320.0070.01116.76
7.2.310.0160.00416.49
7.2.300.0120.00616.44
7.2.290.0110.00716.50
7.2.260.0040.01216.41
7.2.250.0110.00416.83
7.2.240.0070.01016.43
7.2.230.0120.00616.68
7.2.220.0090.00416.75
7.2.210.0000.00916.88
7.2.200.0030.00716.64
7.2.190.0030.01616.76
7.2.180.0070.01416.55
7.2.170.0040.01216.72
7.2.160.0030.01016.65
7.2.150.0100.00318.39
7.2.140.0030.01018.46
7.2.130.0140.00918.27
7.2.120.0140.01018.46
7.2.110.0120.01218.48
7.2.100.0090.01018.43
7.2.90.0120.01218.50
7.2.80.0060.01818.65
7.2.70.0160.00918.45
7.2.60.0070.00917.64
7.2.50.0040.01318.29
7.2.40.0130.01018.44
7.2.30.0030.01718.50
7.2.20.0110.00718.32
7.2.10.0000.01218.35
7.2.00.0100.00718.63
7.1.330.0050.00917.23
7.1.320.0090.00317.46
7.1.310.0070.00717.55
7.1.300.0110.00317.32
7.1.290.0090.00917.54
7.1.280.0040.00417.49
7.1.270.0080.00417.36
7.1.260.0100.00617.45
7.1.250.0040.01717.29
7.1.240.0110.01117.26
7.1.230.0060.01317.29
7.1.220.0090.00917.35
7.1.210.0150.00717.42
7.1.200.0070.00816.45
7.1.190.0120.00917.43
7.1.180.0040.01517.33
7.1.170.0000.01517.31
7.1.160.0090.00917.14
7.1.150.0040.00717.29
7.1.140.0030.01417.33
7.1.130.0030.00717.34
7.1.120.0140.00317.20
7.1.110.0040.01417.24
7.1.100.0040.00917.74
7.1.90.0070.01017.41
7.1.80.0070.00317.32
7.1.70.0050.00517.16
7.1.60.0080.01018.41
7.1.50.0060.01117.06
7.1.40.0000.01417.32
7.1.30.0120.00317.39
7.1.20.0160.00317.55
7.1.10.0040.01217.43
7.1.00.0050.03019.86
7.0.330.0120.00817.16
7.0.320.0100.01016.92
7.0.310.0100.00716.91
7.0.300.0100.00516.89
7.0.290.0070.01016.97
7.0.280.0030.01416.96
7.0.270.0060.00916.86
7.0.260.0100.00717.05
7.0.250.0030.00716.95
7.0.240.0030.00917.06
7.0.230.0060.00917.10
7.0.220.0070.00716.97
7.0.210.0060.00617.12
7.0.200.0070.00816.78
7.0.190.0040.00817.03
7.0.180.0030.00617.20
7.0.170.0040.01117.10
7.0.160.0110.00416.97
7.0.150.0040.01216.98
7.0.140.0040.04119.42
7.0.130.0070.01017.04
7.0.120.0110.00716.90
7.0.110.0060.00917.00
7.0.100.0000.01317.02
7.0.90.0040.00817.06
7.0.80.0030.01016.93
7.0.70.0030.01317.11
7.0.60.0050.04718.42
7.0.50.0060.03817.44
7.0.40.0110.03516.45
7.0.30.0050.04816.30
7.0.20.0090.03416.37
7.0.10.0060.02816.36
7.0.00.0150.03216.31
5.6.400.0090.00916.09
5.6.390.0090.01516.04
5.6.380.0000.01915.79
5.6.370.0080.01316.00
5.6.360.0030.02015.98
5.6.350.0150.00415.69
5.6.340.0030.01315.89
5.6.330.0070.01116.29
5.6.320.0040.01416.14
5.6.310.0080.00816.07
5.6.300.0060.00915.83
5.6.290.0030.01316.32
5.6.280.0060.03918.63
5.6.270.0090.00615.96
5.6.260.0030.01316.05
5.6.250.0130.00616.02
5.6.240.0040.01116.04
5.6.230.0070.01016.17
5.6.220.0060.01216.00
5.6.210.0150.04018.38
5.6.200.0040.04917.13
5.6.190.0150.02517.27
5.6.180.0050.03116.99
5.6.170.0040.03117.07
5.6.160.0090.04417.16
5.6.150.0080.03817.14
5.6.140.0090.04117.18
5.6.130.0070.04217.10
5.6.120.0070.04317.13
5.6.110.0060.03017.13
5.6.100.0040.04617.07
5.6.90.0050.03317.15
5.6.80.0050.03016.80
5.6.70.0070.04316.74
5.6.60.0030.04616.77
5.6.50.0090.02516.84
5.6.40.0080.03616.71
5.6.30.0100.02516.73
5.6.20.0070.04216.76
5.6.10.0120.03616.75
5.6.00.0080.04416.68
5.5.380.0040.00716.05
5.5.370.0120.00015.91
5.5.360.0000.01615.73
5.5.350.0060.04618.09
5.5.340.0050.04716.97
5.5.330.0050.04516.90
5.5.320.0020.02616.97
5.5.310.0080.03716.96
5.5.300.0080.04216.96
5.5.290.0100.04016.91
5.5.280.0090.04516.92
5.5.270.0100.04216.98
5.5.260.0100.03816.96
5.5.250.0110.04016.75
5.5.240.0030.04316.61
5.5.230.0030.03816.56
5.5.220.0090.02416.48
5.5.210.0100.02416.55
5.5.200.0120.03816.66
5.5.190.0140.02016.41
5.5.180.0080.03216.60
5.5.170.0060.00615.85
5.5.160.0050.04516.63
5.5.150.0030.03016.63
5.5.140.0140.04016.65
5.5.130.0080.03816.62
5.5.120.0050.02516.70
5.5.110.0080.04016.60
5.5.100.0030.04116.67
5.5.90.0050.04816.55
5.5.80.0120.02116.55
5.5.70.0070.03216.61
5.5.60.0050.04616.53
5.5.50.0070.02116.45
5.5.40.0020.04116.51
5.5.30.0030.02516.61
5.5.20.0070.04016.46
5.5.10.0020.04216.58
5.5.00.0040.02516.54
5.4.450.0090.02516.14
5.4.440.0100.04016.06
5.4.430.0080.03716.07
5.4.420.0090.04116.02
5.4.410.0100.03315.97
5.4.400.0090.03915.88
5.4.390.0040.03915.97
5.4.380.0050.02615.89
5.4.370.0050.02315.80
5.4.360.0050.02315.91
5.4.350.0080.03515.89
5.4.340.0030.02615.83
5.4.330.0000.01012.91
5.4.320.0070.02815.83
5.4.310.0070.02516.05
5.4.300.0060.03015.87
5.4.290.0030.03515.79
5.4.280.0030.02515.84
5.4.270.0050.02515.97
5.4.260.0050.04315.74
5.4.250.0130.03815.81
5.4.240.0020.02915.77
5.4.230.0050.04315.82
5.4.220.0050.04615.82
5.4.210.0100.03315.76
5.4.200.0030.04115.86
5.4.190.0090.03815.85
5.4.180.0080.02315.73
5.4.170.0090.04015.74
5.4.160.0070.02015.75
5.4.150.0020.02715.79
5.4.140.0060.03714.45
5.4.130.0070.02514.38
5.4.120.0060.02114.56
5.4.110.0060.02014.64
5.4.100.0080.02214.47
5.4.90.0070.02014.50
5.4.80.0030.03814.46
5.4.70.0080.03714.63
5.4.60.0110.02114.46
5.4.50.0080.02714.50
5.4.40.0060.04314.44
5.4.30.0080.03614.56
5.4.20.0020.03914.58
5.4.10.0050.03614.69
5.4.00.0080.03614.25
5.3.290.0020.04514.01
5.3.280.0020.03713.96
5.3.270.0030.04313.88
5.3.260.0040.03713.99
5.3.250.0050.04314.00
5.3.240.0080.03913.84
5.3.230.0000.02513.93
5.3.220.0020.03313.87
5.3.210.0100.01813.85
5.3.200.0070.02213.86
5.3.190.0100.01813.85
5.3.180.0010.04413.89
5.3.170.0000.02913.98
5.3.160.0020.04314.02
5.3.150.0050.03013.91
5.3.140.0030.02313.76
5.3.130.0050.02813.75
5.3.120.0020.03313.90
5.3.110.0070.03313.98
5.3.100.0030.03013.62
5.3.90.0040.04413.55
5.3.80.0070.02913.60
5.3.70.0020.02913.53
5.3.60.0030.03913.55
5.3.50.0070.03713.55
5.3.40.0100.03213.46
5.3.30.0100.03513.46
5.3.20.0030.02513.34
5.3.10.0050.04013.34
5.3.00.0030.04313.35
5.2.170.0000.05011.10
5.2.160.0030.05311.26
5.2.150.0000.05711.22
5.2.140.0070.06311.24
5.2.130.0100.05011.26
5.2.120.0070.03311.25
5.2.110.0130.05711.20
5.2.100.0030.06011.16
5.2.90.0030.03311.06
5.2.80.0070.04311.16
5.2.70.0000.03711.21
5.2.60.0070.03711.08
5.2.50.0030.03311.07
5.2.40.0100.05311.09
5.2.30.0000.04311.07
5.2.20.0100.06011.00
5.2.10.0070.06310.98
5.2.00.0100.03710.82
5.1.60.0030.02710.14
5.1.50.0070.0309.98
5.1.40.0030.04310.11
5.1.30.0030.03710.46
5.1.20.0100.04710.39
5.1.10.0070.06010.21
5.1.00.0100.05310.14
5.0.50.0130.0379.23
5.0.40.0100.0379.23
5.0.30.0000.0709.23
5.0.20.0070.0409.23
5.0.10.0030.0339.23
5.0.00.0100.0579.23
4.4.90.0000.0179.23
4.4.80.0070.0109.23
4.4.70.0000.0439.23
4.4.60.0000.0409.23
4.4.50.0030.0339.23
4.4.40.0030.0379.23
4.4.30.0070.0239.23
4.4.20.0070.0239.23
4.4.10.0070.0339.23
4.4.00.0000.0579.23
4.3.110.0000.0409.23
4.3.100.0070.0209.23
4.3.90.0030.0209.23
4.3.80.0030.0309.23
4.3.70.0030.0239.23
4.3.60.0000.0379.23
4.3.50.0030.0339.23
4.3.40.0030.0439.23
4.3.30.0030.0379.23
4.3.20.0030.0279.23
4.3.10.0000.0309.23
4.3.00.0000.0239.23

preferences:
45.4 ms | 401 KiB | 5 Q