3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace fema\enums; abstract class Enum { protected $name, $ordinal; /** * @return string the name of the enum */ public function name() : string { return $this->name; } /** * @return int a number representing this enum. Starts at 0. */ public function ordinal() : int { return $this->ordinal; } /** * Alias of name() * @return string the name of the enum */ public function __toString() : string { return $this->name(); } /** * @return Enum[] all the enums that are defined in the class */ public abstract static function getAll() : array; /** * Return a specific enum given its name * @param string $name the name of the enum * @return Enum the enum that corresponds to the passed name * @throws EnumNotFoundException if an enum with the passed name is not found */ public static function fromName(string $name) : Enum { foreach (static::getAll() as $item) { if ($item->name() === $name) { return $item; } } throw new EnumNotFoundException("The enum " . static::class . " with name '$name' wasn't found!"); } /** * Return a specific enum given its ordinal * @param int $ordinal the ordinal of the enum * @return Enum the enum that corresponds to the passed ordinal * @throws EnumNotFoundException if an enum with the passed ordinal is not found */ public static function fromOrdinal(int $ordinal) : Enum { foreach (static::getAll() as $item) { if ($item->ordinal() === $ordinal) { return $item; } } throw new EnumNotFoundException("The enum " . static::class . " with ordinal '$ordinal' wasn't found!"); } } abstract class DocEnum extends Enum { protected static $enums = []; private function __construct() { } /** * @inheritDoc */ public static function getAll() : array { return static::getOrLoad(static::class); } private static function getOrLoad(string $class) { if (!isset(self::$enums[$class])) { $cls = new \ReflectionClass($class); if ($cls->getParentClass()->getName() !== self::class) { $enums = static::getOrLoad($cls->getParentClass()->getName()); } else { $enums = []; } $ordinal = count($enums); $doc = $cls->getDocComment(); if ($doc !== false) { $matches = []; if (preg_match_all('/^\\s*\\*\\s*@method\\s+static\\s+([A-Z]+)\\(\\s*\\)\\s*$/m', $doc, $matches) > 0) { foreach ($matches[1] as $name) { $enum = new $class(); $enum->name = $name; $enum->ordinal = $ordinal++; $enums[] = $enum; } } } static::$enums[$class] = $enums; } return static::$enums[$class]; } } /** * * @method static MONDAY() * @method static TUESDAY() * @method static WENSDAY() * @method static THURSDAY() * @method static FRIDAY() */ class WorkDays extends DocEnum { } /** * @method static SATURDAY() * @method static SUNDAY() */ class Days extends WorkDays { } var_dump(WorkDays::getAll()); var_dump(Days::getAll());

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.0100.01018.55
8.3.50.0040.01216.66
8.3.40.0030.01319.22
8.3.30.0120.00318.92
8.3.20.0000.00820.34
8.3.10.0050.00321.94
8.3.00.0060.00619.65
8.2.180.0150.00018.55
8.2.170.0000.01522.96
8.2.160.0150.00320.44
8.2.150.0030.00524.18
8.2.140.0030.00624.66
8.2.130.0040.00421.12
8.2.120.0080.00026.35
8.2.110.0070.00321.16
8.2.100.0090.00318.03
8.2.90.0040.00419.32
8.2.80.0030.00517.97
8.2.70.0030.00618.05
8.2.60.0080.00018.22
8.2.50.0050.00318.10
8.2.40.0040.00420.54
8.2.30.0030.00521.05
8.2.20.0000.00818.21
8.2.10.0040.00418.36
8.2.00.0030.00518.23
8.1.280.0100.01025.92
8.1.270.0080.00023.97
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0030.00619.78
8.1.230.0110.00019.14
8.1.220.0070.00317.91
8.1.210.0070.00418.77
8.1.200.0030.00617.60
8.1.190.0040.00417.48
8.1.180.0000.00818.10
8.1.170.0070.00318.89
8.1.160.0000.00819.04
8.1.150.0080.00018.95
8.1.140.0000.00719.61
8.1.130.0000.00718.91
8.1.120.0050.00217.66
8.1.110.0060.00317.73
8.1.100.0040.00417.66
8.1.90.0040.00417.55
8.1.80.0040.00417.55
8.1.70.0040.00417.62
8.1.60.0030.00617.82
8.1.50.0040.00417.77
8.1.40.0050.00317.61
8.1.30.0000.00817.76
8.1.20.0060.00317.78
8.1.10.0000.00817.66
8.1.00.0040.00417.58
8.0.300.0060.00321.77
8.0.290.0000.00817.00
8.0.280.0000.00718.48
8.0.270.0000.00817.32
8.0.260.0050.00316.93
8.0.250.0030.00317.14
8.0.240.0050.00217.10
8.0.230.0040.00417.05
8.0.220.0000.00817.09
8.0.210.0050.00217.06
8.0.200.0040.00417.13
8.0.190.0000.00917.08
8.0.180.0000.00717.04
8.0.170.0000.00716.99
8.0.160.0040.00417.04
8.0.150.0000.00717.04
8.0.140.0040.00417.02
8.0.130.0030.00313.60
8.0.120.0000.00717.06
8.0.110.0040.00417.11
8.0.100.0030.00517.13
8.0.90.0000.00817.06
8.0.80.0060.01217.00
8.0.70.0000.00717.08
8.0.60.0040.00416.96
8.0.50.0030.00516.95
8.0.30.0090.01017.29
8.0.20.0100.01117.40
8.0.10.0040.00417.07
8.0.00.0130.00717.02
7.4.330.0050.00015.55
7.4.320.0000.00816.77
7.4.300.0000.00616.88
7.4.290.0000.01016.76
7.4.280.0030.00616.66
7.4.270.0000.00716.65
7.4.260.0000.00613.54
7.4.250.0050.00516.73
7.4.240.0090.00016.80
7.4.230.0000.00716.77
7.4.220.0030.01716.75
7.4.210.0070.01416.84
7.4.200.0070.00016.96
7.4.160.0080.01116.69
7.4.150.0120.00917.40
7.4.140.0150.00817.86
7.4.130.0070.01416.86
7.4.120.0120.00716.76
7.4.110.0100.01016.65
7.4.100.0070.01116.79
7.4.90.0090.01016.77
7.4.80.0060.01219.39
7.4.70.0180.00016.68
7.4.60.0100.00916.68
7.4.50.0070.00716.70
7.4.40.0080.01216.59
7.4.30.0080.01016.91
7.4.10.0080.00815.29
7.4.00.0090.00615.21
7.3.330.0030.00313.52
7.3.320.0070.00013.59
7.3.310.0000.00816.46
7.3.300.0040.00416.57
7.3.290.0090.01016.56
7.3.280.0070.01116.56
7.3.270.0050.01517.40
7.3.260.0080.01316.56
7.3.250.0120.00916.63
7.3.240.0100.00816.89
7.3.230.0100.01616.82
7.3.210.0090.00916.79
7.3.200.0140.00316.91
7.3.190.0190.00016.55
7.3.180.0090.00916.89
7.3.170.0170.00016.73
7.3.160.0120.00916.82
7.3.130.0030.01715.26
7.3.120.0060.00615.04
7.3.110.0070.01315.00
7.3.100.0060.01015.37
7.3.90.0100.00715.14
7.3.80.0030.00614.99
7.3.70.0130.00315.18
7.3.60.0140.00415.12
7.3.50.0070.01014.92
7.3.40.0140.00014.73
7.3.30.0060.00914.91
7.3.20.0060.00916.73
7.3.10.0040.00816.85
7.3.00.0000.01116.88
7.2.330.0070.01417.01
7.2.320.0090.01316.86
7.2.310.0110.00716.79
7.2.300.0060.01617.05
7.2.290.0090.00916.84
7.2.260.0000.02115.55
7.2.250.0100.00715.32
7.2.240.0060.00915.23
7.2.230.0030.01415.45
7.2.220.0080.00615.15
7.2.210.0040.00715.53
7.2.200.0040.01215.21
7.2.190.0080.00415.46
7.2.180.0080.00415.28
7.2.170.0000.01015.34
7.2.160.0090.00015.39
7.2.150.0100.00717.39
7.2.140.0030.01317.18
7.2.130.0040.01517.21
7.2.120.0100.01016.88
7.2.110.0100.01017.13
7.2.100.0070.00317.17
7.2.90.0060.01017.13
7.2.80.0040.01417.27
7.2.70.0030.00717.35
7.2.60.0090.00617.21
7.2.50.0060.01017.00
7.2.40.0060.01016.90
7.2.30.0090.00917.10
7.2.20.0090.00617.24
7.2.10.0080.00817.20
7.2.00.0020.00918.56
7.1.330.0130.00015.84
7.1.320.0040.01216.19
7.1.310.0090.00616.14
7.1.300.0040.00715.91
7.1.290.0100.00315.87
7.1.280.0060.00916.09
7.1.270.0060.00916.13
7.1.260.0060.00615.63
7.1.250.0060.01016.16
7.1.240.0130.00316.15
7.1.230.0090.01015.75
7.1.220.0040.01116.11
7.1.210.0000.01616.20
7.1.200.0070.00615.98
7.1.190.0000.01415.78
7.1.180.0030.01015.75
7.1.170.0000.01516.10
7.1.160.0040.01116.18
7.1.150.0000.01316.13
7.1.140.0100.00616.02
7.1.130.0070.01016.07
7.1.120.0000.01016.10
7.1.110.0060.00915.85
7.1.100.0080.00717.27
7.1.90.0140.00016.12
7.1.80.0040.00816.13
7.1.70.0030.01016.68
7.1.60.0140.01025.51
7.1.50.0140.01225.37
7.1.40.0130.01225.38
7.1.30.0110.01125.38
7.1.20.0120.01225.32
7.1.10.0050.01116.35
7.1.00.0070.00716.54
7.0.330.0040.00815.60
7.0.320.0000.01415.57
7.0.310.0120.00015.52
7.0.300.0060.00915.53
7.0.290.0000.01015.69
7.0.280.0040.00815.67
7.0.270.0040.01115.41
7.0.260.0000.01415.74
7.0.250.0060.00915.50
7.0.240.0040.00715.80
7.0.230.0070.00715.86
7.0.220.0000.00915.45
7.0.210.0000.01215.85
7.0.200.0060.00616.32
7.0.190.0050.00916.26
7.0.180.0070.01116.12
7.0.170.0030.01116.11
7.0.160.0060.00715.96
7.0.150.0050.01215.96
7.0.140.0030.01516.17
7.0.130.0030.01316.15
7.0.120.0030.01116.21
7.0.110.0110.00415.98
7.0.100.0050.00916.16
7.0.90.0040.01216.06
7.0.80.0080.00715.85
7.0.70.0020.01416.15
7.0.60.0060.01116.18
7.0.50.0100.00716.04
7.0.40.0030.01315.14
7.0.30.0030.01115.18
7.0.20.0080.01015.18
7.0.10.0060.00715.17
7.0.00.0070.00515.17
5.6.400.0060.00914.08
5.6.390.0120.00614.30
5.6.380.0070.00714.14
5.6.370.0030.00914.25
5.6.360.0000.01313.83
5.6.350.0000.01414.11
5.6.340.0070.00714.11
5.6.330.0030.00914.03
5.6.320.0040.00414.16
5.6.310.0100.00314.06
5.6.300.0030.01314.20
5.6.290.0030.00914.25
5.6.280.0000.01914.08
5.6.270.0030.01014.29
5.6.260.0060.00614.10
5.6.250.0040.01214.05
5.6.240.0070.00714.21
5.6.230.0040.01114.27
5.6.220.0000.00914.16
5.6.210.0090.00614.22
5.6.200.0100.00614.19
5.6.190.0070.00414.30
5.6.180.0060.00614.16
5.6.170.0060.00613.94
5.6.160.0100.00314.11
5.6.150.0120.00314.42
5.6.140.0080.00814.02
5.6.130.0090.00914.24
5.6.120.0060.01214.05
5.6.110.0090.00913.87
5.6.100.0030.01014.00
5.6.90.0080.00414.14
5.6.80.0130.00313.96
5.6.70.0030.01013.80
5.6.60.0090.00013.93
5.6.50.0100.00314.29
5.6.40.0030.00713.92
5.6.30.0000.01414.11
5.6.20.0060.00613.89
5.6.10.0110.00413.91
5.6.00.0030.00613.99

preferences:
43.09 ms | 400 KiB | 5 Q