3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Derp; abstract class Enum { protected $value; protected static $possibleValues; protected static function getPossibleValues() { if (static::$possibleValues) { return static::$possibleValues; } $reflectionClass = new \ReflectionClass(get_called_class()); static::$possibleValues = $reflectionClass->getConstants(); return static::$possibleValues; } /** * @param $name * @param $arguments * @return static * @throws \Exception */ public static function __callStatic($name, $arguments) { $possibleValues = static::getPossibleValues(); if (!array_key_exists($name, $possibleValues)) { throw new \Exception; } if (count($arguments) > 0) { throw new \Exception; } return self::createInstance($name, $possibleValues[$name]); } /** * @param $value * @return static */ protected static function createInstance($value) { $enum = new static; $enum->value = $value; return $enum; } protected function getValue() { return $this->value; } public function equals(Enum $otherValue) { return get_class($otherValue) === get_called_class() && $otherValue->getValue() === $this->getValue(); } public static function all() { return array_map( function($value) { return static::createInstance($value); }, static::getPossibleValues() ); } } class Day extends Enum { const MONDAY = 'monday'; const FRIDAY = 'friday'; } $monday = Day::MONDAY(); var_dump($monday); var_dump($monday->equals(Day::FRIDAY())); var_dump(Day::all());

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.70.0120.00618.43
8.3.60.0100.01018.43
8.3.50.0150.00721.99
8.3.40.0110.00418.90
8.3.30.0070.00719.05
8.3.20.0040.00420.25
8.3.10.0040.00421.80
8.3.00.0000.00819.14
8.2.190.0110.00416.58
8.2.180.0060.01016.63
8.2.170.0100.01022.96
8.2.160.0070.01122.30
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0000.00726.16
8.2.120.0040.00419.79
8.2.110.0030.00620.29
8.2.100.0080.00419.40
8.2.90.0000.00919.27
8.2.80.0040.00417.97
8.2.70.0060.00317.50
8.2.60.0000.00818.04
8.2.50.0050.00318.07
8.2.40.0060.00320.07
8.2.30.0070.00018.16
8.2.20.0000.00717.68
8.2.10.0040.00418.03
8.2.00.0080.00017.66
8.1.280.0040.01125.92
8.1.270.0060.00318.95
8.1.260.0030.00626.35
8.1.250.0070.00028.09
8.1.240.0090.00021.91
8.1.230.0080.00319.09
8.1.220.0080.00017.76
8.1.210.0000.00818.77
8.1.200.0000.01017.36
8.1.190.0040.00417.23
8.1.180.0080.00018.10
8.1.170.0040.00418.72
8.1.160.0000.00722.04
8.1.150.0070.00018.97
8.1.140.0080.00019.23
8.1.130.0030.00317.78
8.1.120.0000.00817.39
8.1.110.0040.00417.50
8.1.100.0020.00517.47
8.1.90.0000.00717.39
8.1.80.0000.00717.51
8.1.70.0070.00017.38
8.1.60.0040.00417.62
8.1.50.0000.00817.52
8.1.40.0000.00717.50
8.1.30.0060.00317.55
8.1.20.0090.00017.75
8.1.10.0060.00317.52
8.1.00.0040.00417.47
8.0.300.0070.00018.77
8.0.290.0060.00316.75
8.0.280.0040.00418.37
8.0.270.0080.00017.25
8.0.260.0000.00817.34
8.0.250.0070.00016.91
8.0.240.0050.00317.07
8.0.230.0000.00716.94
8.0.220.0040.00416.97
8.0.210.0000.00816.87
8.0.200.0000.00617.02
8.0.190.0080.00017.00
8.0.180.0050.00317.05
8.0.170.0000.00716.91
8.0.160.0050.00216.88
8.0.150.0040.00416.89
8.0.140.0040.00416.95
8.0.130.0000.00613.41
8.0.120.0050.00316.96
8.0.110.0050.00316.99
8.0.100.0000.00716.97
8.0.90.0000.00717.01
8.0.80.0160.00716.95
8.0.70.0040.00416.75
8.0.60.0000.00717.04
8.0.50.0040.00416.94
8.0.30.0100.01117.34
8.0.20.0090.01317.40
8.0.10.0040.00417.11
8.0.00.0120.00816.98
7.4.330.0000.00515.05
7.4.320.0040.00416.48
7.4.300.0030.00316.65
7.4.290.0000.00716.58
7.4.280.0030.00716.45
7.4.270.0070.00016.44
7.4.260.0000.00613.30
7.4.250.0040.00416.49
7.4.240.0030.00416.59
7.4.230.0000.00716.38
7.4.220.0090.00816.59
7.4.210.0110.00416.48
7.4.200.0070.00016.36
7.4.160.0080.00816.68
7.4.150.0030.01717.40
7.4.140.0140.00717.86
7.4.130.0110.00616.52
7.4.120.0110.00616.62
7.4.110.0120.01216.74
7.4.100.0160.00716.42
7.4.90.0090.00916.57
7.4.80.0090.01219.39
7.4.70.0090.01816.68
7.4.60.0030.01316.43
7.4.50.0030.00516.60
7.4.40.0110.00616.47
7.4.30.0070.01016.56
7.4.00.0130.00314.92
7.3.330.0030.00313.20
7.3.320.0030.00413.34
7.3.310.0000.00716.44
7.3.300.0070.00016.43
7.3.290.0070.00916.38
7.3.280.0040.01316.32
7.3.270.0080.00917.40
7.3.260.0090.00916.40
7.3.250.0080.01116.41
7.3.240.0150.00416.39
7.3.230.0150.00416.39
7.3.210.0100.00616.31
7.3.200.0130.00919.39
7.3.190.0120.00616.54
7.3.180.0030.01916.34
7.3.170.0090.00916.60
7.3.160.0110.00616.48
7.2.330.0090.01016.58
7.2.320.0120.00916.44
7.2.310.0140.00316.79
7.2.300.0030.02016.80
7.2.290.0150.00816.79
7.2.00.0030.00919.27
7.1.100.0030.01017.98
7.1.70.0030.00716.86
7.1.60.0100.01319.46
7.1.50.0110.01116.63
7.1.00.0100.07022.36
7.0.200.0000.00716.52
7.0.140.0030.07722.02
7.0.60.0330.06020.04
7.0.50.0130.08017.90
7.0.40.0100.07320.39
7.0.30.0270.06720.21
7.0.20.0200.09020.23
7.0.10.0070.06020.23
7.0.00.0030.04020.20
5.6.280.0000.07321.04
5.6.210.0000.04320.49
5.6.200.0030.07718.19
5.6.190.0070.06020.64
5.6.180.0400.07020.52
5.6.170.0370.06720.39
5.6.160.0100.06318.18
5.6.150.0030.09018.19
5.6.140.0170.06718.24
5.6.130.0100.03318.18
5.6.120.0070.07721.02
5.6.110.0130.08320.91
5.6.100.0030.08320.91
5.6.90.0170.07021.00
5.6.80.0130.03320.45
5.5.350.0230.07320.38
5.5.340.0030.04018.09
5.5.330.0100.05020.49
5.5.320.0170.04720.51
5.5.310.0230.04320.24
5.5.300.0100.05018.04
5.5.290.0070.08017.99
5.5.280.0000.05020.92
5.5.270.0030.06720.75
5.5.260.0100.08320.86
5.5.250.0100.07720.61
5.5.240.3670.04320.18
5.4.450.0270.06019.49
5.4.440.0500.06719.44
5.4.430.0270.04019.21
5.4.420.0070.06019.37
5.4.410.0100.05319.42
5.4.400.0030.06018.92
5.4.390.0270.07318.85
5.4.380.0230.07318.68
5.4.370.0370.06718.73
5.4.360.0300.05718.61
5.4.350.0200.06318.54
5.4.340.0270.05318.58
5.4.320.0400.06018.79
5.4.310.0630.06018.80
5.4.300.0400.06018.84
5.4.290.0270.05318.53
5.4.280.0130.06018.62
5.4.270.0200.05718.80
5.4.260.0230.05018.78
5.4.250.0270.06018.85
5.4.240.0230.07318.58
5.4.230.0130.08018.53
5.4.220.0330.05018.56
5.4.210.0300.04718.70
5.4.200.0170.05316.68
5.4.190.0200.06318.73
5.4.180.0300.06318.74
5.4.170.0230.06718.57
5.4.160.0200.06018.78
5.4.150.0330.06018.71
5.4.140.0200.06316.48
5.4.130.0200.05016.29
5.4.120.0100.06316.46
5.4.110.0230.05016.22
5.4.100.0330.05016.30
5.4.90.0200.05316.26
5.4.80.0270.05716.44
5.4.70.0270.05016.16
5.4.60.0230.05016.31
5.4.50.0170.05016.29
5.4.40.0200.05016.18
5.4.30.0200.05016.43
5.4.20.0270.07016.31
5.4.10.0230.05316.20
5.4.00.0230.04315.71
5.3.290.0100.07314.67
5.3.280.0130.07714.82
5.3.270.0230.05314.69
5.3.260.0170.06014.68
5.3.250.0230.05714.82
5.3.240.0300.07014.73
5.3.230.0230.05314.65
5.3.220.0170.05714.70
5.3.210.0270.06014.67
5.3.200.0230.05014.80
5.3.190.0170.06014.59
5.3.180.0270.06314.61
5.3.170.0230.05014.76
5.3.160.0200.07314.67
5.3.150.0100.06314.87
5.3.140.0100.06314.59
5.3.130.0330.07314.67
5.3.120.0130.06014.77
5.3.110.0130.06314.63
5.3.100.0230.05314.24
5.3.90.0200.05014.25
5.3.80.0200.05314.04
5.3.70.0230.05714.04
5.3.60.0200.07014.19
5.3.50.0170.07314.09
5.3.40.0270.05314.16
5.3.30.0230.05013.93
5.3.20.0130.06013.78
5.3.10.0170.05713.77
5.3.00.0230.05013.76
5.2.170.0170.04311.30
5.2.160.0130.05011.12
5.2.150.0100.05311.14
5.2.140.0230.05011.07
5.2.130.0170.04011.23
5.2.120.0070.04711.10
5.2.110.0230.03711.03
5.2.100.0200.04711.04
5.2.90.0130.04711.09
5.2.80.0100.04711.13
5.2.70.0130.06011.01
5.2.60.0130.04711.13
5.2.50.0200.05010.96
5.2.40.0130.04310.92
5.2.30.0300.03711.01
5.2.20.0230.04710.95
5.2.10.0170.04710.96
5.2.00.0100.04710.69
5.1.60.0100.04710.02
5.1.50.0230.04010.02
5.1.40.0100.03710.11
5.1.30.0100.04310.30
5.1.20.0100.04710.39
5.1.10.0100.04710.09
5.1.00.0170.03710.07
5.0.50.0100.0338.53
5.0.40.0170.0208.43
5.0.30.0070.0478.34
5.0.20.0130.0278.23
5.0.10.0100.0308.16
5.0.00.0130.0478.34
4.4.90.0100.0205.92
4.4.80.0170.0205.90
4.4.70.0070.0235.86
4.4.60.0100.0205.91
4.4.50.0100.0205.88
4.4.40.0030.0435.88
4.4.30.0030.0275.81
4.4.20.0100.0205.96
4.4.10.0070.0235.93
4.4.00.0100.0435.85
4.3.110.0130.0235.86
4.3.100.0100.0235.75
4.3.90.0100.0205.80
4.3.80.0070.0375.78
4.3.70.0170.0205.82
4.3.60.0100.0305.77
4.3.50.0100.0235.82
4.3.40.0170.0305.84
4.3.30.0030.0274.59
4.3.20.0000.0304.57
4.3.10.0030.0274.49
4.3.00.0100.02012.45

preferences:
41.36 ms | 401 KiB | 5 Q