3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php namespace texdc\cicerone; /** * Provides encapsulation and validation of HTTP method values * * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html */ final class HttpMethod { /**#@+ * method constants * @var string */ const ANY = '*'; const GET = 'GET'; const HEAD = 'HEAD'; const POST = 'POST'; const PUT = 'PUT'; const DELETE = 'DELETE'; const OPTIONS = 'OPTIONS'; const TRACE = 'TRACE'; /**#@- */ /** @var string[] */ private static $allValues = [ self::ANY, self::GET, self::HEAD, self::POST, self::PUT, self::DELETE, self::OPTIONS, self::TRACE, ]; /** @var self[] */ private static $instances = []; /** @var string */ private $value; /** * @param string $aValue * @throws InvalidArgumentException */ private function HttpMethod($aValue) { if (!self::validate($aValue)) { throw new InvalidArgumentException("Invalid method [$aValue]"); } $this->value = self::sanitize($aValue); } /** * @param string $aMethod * @param array $arguments * @return self */ public static function __callStatic($aMethod, $arguments = []) { if (!isset(self::$instances[$aMethod]) && $instance = new static($aMethod)) { self::$instances[$aMethod] = $instance; } var_dump($aMethod, $instance); return self::$instances[$aMethod]; } /** * @param string $aValue * @return string */ private static function sanitize($aValue) { return strtoupper(trim($aValue)); } /** * @param string $aValue * @return bool */ public static function validate($aValue) { return in_array(self::sanitize($aValue), self::$allValues); } /** * @param string $aValue * @return bool */ public function hasValue($aValue) { return $this->value === (string) $aValue; } /** @return bool */ public function isAny() { return $this->hasValue(self::ANY); } /** @return bool */ public function isGet() { return $this->hasValue(self::GET) || $this->isAny(); } /** @return bool */ public function isHead() { return $this->hasValue(self::HEAD) || $this->isAny(); } /** @return bool */ public function isPost() { return $this->hasValue(self::POST) || $this->isAny(); } /** @return bool */ public function isPut() { return $this->hasValue(self::PUT) || $this->isAny(); } /** @return bool */ public function isDelete() { return $this->hasValue(self::DELETE) || $this->isAny(); } /** @return bool */ public function isOptions() { return $this->hasValue(self::OPTIONS) || $this->isAny(); } /** @return bool */ public function isTrace() { return $this->hasValue(self::TRACE) || $this->isAny(); } /** @return string */ public function __toString() { return $this->value; } } var_dump(HttpMethod::PUT());
based on 2I92G

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.3.10.0150.00716.64
7.3.00.0110.01116.58
7.2.130.0170.00916.83
7.2.120.0180.00616.92
7.2.110.0110.01016.77
7.2.100.0140.00816.97
7.2.90.0150.00717.03
7.2.80.0070.01416.78
7.2.70.0120.01316.92
7.2.60.0110.00916.81
7.2.50.0190.00816.94
7.2.40.0170.00516.80
7.2.30.0170.00916.94
7.2.20.0210.00216.76
7.2.10.0140.00816.77
7.2.00.0080.00617.68
7.1.250.0060.01315.68
7.1.200.0070.01615.66
7.1.100.0080.00518.04
7.1.70.0060.00916.87
7.1.60.0150.01119.50
7.1.50.0100.01016.92
7.1.00.0000.07722.28
7.0.200.0030.00516.89
7.0.140.0100.06721.95
7.0.60.0100.05719.99
7.0.50.0130.07317.93
7.0.40.0100.07320.30
7.0.30.0130.04720.17
7.0.20.0300.05720.10
7.0.10.0270.07020.22
7.0.00.0070.04020.09
5.6.280.0100.06721.11
5.6.210.0100.07720.66
5.6.200.0130.07318.19
5.6.190.0170.08720.38
5.6.180.0300.06020.75
5.6.170.0430.07320.71
5.6.160.0030.07020.52
5.6.150.0000.04318.16
5.6.140.0030.03718.21
5.6.130.0130.08018.24
5.6.120.0100.08021.02
5.6.110.0100.08020.98
5.6.100.0000.06021.16
5.6.90.0170.07321.11
5.6.80.0130.07720.31
5.6.70.0400.05720.55
5.5.350.0130.08020.47
5.5.340.0030.05318.00
5.5.330.0070.09020.47
5.5.320.0070.07020.29
5.5.310.0370.06720.19
5.5.300.0070.06317.99
5.5.290.0070.08318.09
5.5.280.0030.04020.79
5.5.270.0100.07720.89
5.5.260.0030.05020.79
5.5.250.0000.08320.80
5.5.240.0070.06020.31
5.4.450.0770.05319.57
5.4.440.0900.05719.17
5.4.430.0070.05719.50
5.4.420.0830.04719.31
5.4.410.0600.07019.32
5.4.400.0270.05718.62
5.4.390.0330.06718.78
5.4.380.0400.04318.72
5.4.370.0270.05718.80
5.4.360.0300.05318.82
5.4.350.0230.07018.50
5.4.340.0230.05318.62
5.4.320.0300.05318.55
5.4.310.0230.05718.75
5.4.300.0230.05018.78
5.4.290.0330.04718.80
5.4.280.0300.04318.79
5.4.270.0200.05718.60
5.4.260.0300.04318.83
5.4.250.0170.05718.56
5.4.240.0230.05018.54
5.4.230.0230.05318.51
5.4.220.0200.05318.76
5.4.210.0200.05318.59
5.4.200.0200.05016.62
5.4.190.0300.04318.71
5.4.180.0270.05018.57
5.4.170.0270.06718.76
5.4.160.0230.05718.57
5.4.150.0300.05718.56
5.4.140.0300.05016.48
5.4.130.0270.04316.32
5.4.120.0330.04016.22
5.4.110.0200.05316.29
5.4.100.0300.04716.36
5.4.90.0300.04716.23
5.4.80.0270.04716.18
5.4.70.0270.06016.17
5.4.60.0270.05716.33
5.4.50.0270.05316.24
5.4.40.0170.06316.18
5.4.30.0330.04716.43
5.4.20.0230.05016.25
5.4.10.0270.05016.31
5.4.00.0300.04715.71
5.3.290.0270.05714.66
5.3.280.0300.05014.81
5.3.270.0330.05314.64
5.3.260.0170.06314.71
5.3.250.0370.05314.62
5.3.240.0330.04314.72
5.3.230.0300.04314.63
5.3.220.0330.04714.62
5.3.210.0200.07014.56
5.3.200.0370.03714.69
5.3.190.0200.05314.62
5.3.180.0170.05714.78
5.3.170.0130.06714.59
5.3.160.0300.04714.70
5.3.150.0270.05014.69
5.3.140.0230.05014.76
5.3.130.0230.05314.59
5.3.120.0270.05014.57
5.3.110.0100.06314.64
5.3.100.0270.05014.03
5.3.90.0270.05014.00
5.3.80.0170.06014.11
5.3.70.0230.05014.14
5.3.60.0130.06014.20
5.3.50.0200.05014.14
5.3.40.0130.07013.96
5.3.30.0330.04313.95
5.3.20.0170.05313.86
5.3.10.0330.05013.77
5.3.00.0270.04713.84
5.2.170.0200.04011.20
5.2.160.0130.04711.13
5.2.150.0230.04311.07
5.2.140.0130.04711.12
5.2.130.0170.04311.10
5.2.120.0170.04311.24
5.2.110.0170.04311.03
5.2.100.0230.03311.24
5.2.90.0170.04011.09
5.2.80.0130.04711.04
5.2.70.0170.04711.13
5.2.60.0130.04711.04
5.2.50.0170.04011.05
5.2.40.0100.04311.05
5.2.30.0130.04310.95
5.2.20.0170.04011.11
5.2.10.0100.04710.89
5.2.00.0170.05010.77
5.1.60.0170.03310.05
5.1.50.0200.02710.10
5.1.40.0130.0339.99
5.1.30.0100.04010.43
5.1.20.0130.04310.45
5.1.10.0200.03010.10
5.1.00.0100.04010.16
5.0.50.0130.0238.68
5.0.40.0100.0278.53
5.0.30.0130.0408.20
5.0.20.0070.0308.19
5.0.10.0100.0278.27
5.0.00.0070.0438.36
4.4.90.0070.0237.51
4.4.80.0100.0207.51
4.4.70.0070.0237.51
4.4.60.0070.0237.51
4.4.50.0100.0207.51
4.4.40.0070.0377.51
4.4.30.0030.0277.51
4.4.20.0100.0237.51
4.4.10.0130.0207.51
4.4.00.0070.0377.51
4.3.110.0030.0277.51
4.3.100.0100.0177.51
4.3.90.0100.0207.51
4.3.80.0170.0337.51
4.3.70.0100.0207.51
4.3.60.0130.0177.51
4.3.50.0070.0237.51
4.3.40.0100.0307.51
4.3.30.0030.0237.51
4.3.20.0030.0237.51
4.3.10.0000.0277.51
4.3.00.0100.0209.29