3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * AbstractError.php * * @package WordPress\Error */ namespace WordPress\Error; use InvalidArgumentException; use RuntimeException; /** * WordPress Errors extend {@link RuntimeException} with relevant data. * * Extend this class with domain-specific codes and messages and call this * constructor to include the instance in the list of recorded errors. * * Use {@link is_wp_error()} to check if this class is returned. Many core * WordPress functions pass this class in the event of an error and if not * handled properly will result in code errors. * * @package WordPress\Error * @since 2.1.0 */ abstract class AbstractError extends RuntimeException { /** * Internal map of code messages * * @var array code (int) => message (string) */ protected static $codeMessages = []; /** * Internal list of AbstractError instances * * @var self[] */ private static $instances = []; /** * Optional error data * * @var mixed */ private $data; /** * Initialize the error * * @param int $code an error code * @param mixed $data optional error data * @param self $previous optional previous error * * @throws InvalidArgumentException when the code is not recognized */ public function __construct($code, $data = null, self $previous = null) { if (!isset(static::$codeMessages[$code])) { throw new InvalidArgumentException("Invalid error code [$code]"); } parent::__construct(static::$codeMessages[$code], $code, $previous); $this->data = $data; self::$instances[] = $this; } /** * Remove all instances having the specified code * * @param int $code an error code to remove */ final public static function remove($code) { foreach (self::$instances as $index => $error) { if ($code === $error->getCode()) { unset(self::$instances[$index]); } } } /** * Retrieve all instances having the specified code * * @param int $code an error code * * @yield self each error instance with matching code */ final public static function get($code) { foreach (self::$instances as $error) { if ($code === $error->getCode()) { yield $error; } } } /** * Retrieve all error instances * * @yield self each error instance */ final public static function getAll() { foreach (self::$instances as $error) { yield $error; } } /** * Retrieve the error data * * @return mixed error data, if available */ public function getData() { return $this->data; } /** * Replace the error data * * @param mixed $data optional error data * * @return self an instance with the new data */ public function setData($data = null) { return new static($this->getCode(), $data, $this); } /** * Triggers a PHP error * * @param int $type optional PHP error type */ public function trigger($type = E_USER_NOTICE) { trigger_error((string) $this, (int) $type); } /** * Converts the object to a string * * @return string a formatted error string */ public function __toString() { return "Error " . $this->getCode() . ": " . $this->getMessage(); } } class E extends AbstractError { protected static $codeMessages = [ 5001 => 'foo', 6001 => 'bar' ]; public static function foo($data = null) { return new static(5001, $data); } public static function bar($data = null) { return new static(6001, $data); } } $e = E::foo(); $s = $e->setData('snowflake'); foreach (E::getAll() as $error) { echo $error . PHP_EOL; } var_dump($e, $s);

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.68
8.3.50.0060.01017.99
8.3.40.0070.01418.79
8.3.30.0040.01119.01
8.3.20.0080.00020.39
8.3.10.0080.00021.77
8.3.00.0000.00919.38
8.2.180.0060.01018.16
8.2.170.0060.00922.96
8.2.160.0140.00020.39
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0100.00026.16
8.2.120.0080.00019.48
8.2.110.0080.00319.25
8.2.100.0060.00617.75
8.2.90.0080.00019.35
8.2.80.0000.00817.97
8.2.70.0060.00317.75
8.2.60.0030.00618.05
8.2.50.0000.00918.07
8.2.40.0040.00420.01
8.2.30.0040.00418.13
8.2.20.0000.00817.76
8.2.10.0000.00818.06
8.2.00.0040.00417.70
8.1.280.0060.00925.92
8.1.270.0030.00620.63
8.1.260.0040.00426.35
8.1.250.0060.00328.09
8.1.240.0050.00522.02
8.1.230.0070.00417.66
8.1.220.0050.00317.77
8.1.210.0000.00818.77
8.1.200.0050.00517.35
8.1.190.0000.00817.25
8.1.180.0080.00018.10
8.1.170.0000.01018.75
8.1.160.0040.00422.04
8.1.150.0040.00418.92
8.1.140.0040.00417.48
8.1.130.0000.00717.86
8.1.120.0080.00417.39
8.1.110.0000.00817.41
8.1.100.0040.00417.36
8.1.90.0050.00217.48
8.1.80.0000.00717.48
8.1.70.0070.00017.50
8.1.60.0090.00017.50
8.1.50.0000.00917.54
8.1.40.0040.00717.58
8.1.30.0030.00617.58
8.1.20.0040.00417.58
8.1.10.0040.00417.63
8.1.00.0030.00517.53
8.0.300.0050.00218.77
8.0.290.0080.00016.75
8.0.280.0080.00018.39
8.0.270.0040.00417.21
8.0.260.0070.00017.29
8.0.250.0040.00317.02
8.0.240.0040.00417.02
8.0.230.0040.00416.97
8.0.220.0070.00016.82
8.0.210.0000.00716.81
8.0.200.0070.00017.00
8.0.190.0040.00416.95
8.0.180.0050.00216.91
8.0.170.0040.00416.90
8.0.160.0000.00716.94
8.0.150.0030.00616.91
8.0.140.0040.00416.91
8.0.130.0030.00313.44
8.0.120.0000.00916.79
8.0.110.0060.00316.86
8.0.100.0030.00516.87
8.0.90.0000.00916.96
8.0.80.0030.01216.91
8.0.70.0040.00416.96
8.0.60.0090.00016.87
8.0.50.0060.00316.98
8.0.30.0160.00816.82
8.0.20.0090.01117.40
8.0.10.0050.00316.88
8.0.00.0140.00716.78
7.4.330.0000.00515.03
7.4.320.0030.00316.56
7.4.300.0030.00316.59
7.4.290.0060.00316.66
7.4.280.0040.00416.63
7.4.270.0000.00716.51
7.4.260.0030.00516.52
7.4.250.0030.00516.61
7.4.240.0020.00616.49
7.4.230.0030.00416.46
7.4.220.0130.01416.51
7.4.210.0030.01416.59
7.4.200.0040.00416.52
7.4.160.0070.01116.54
7.4.150.0130.01317.40
7.4.140.0140.01117.86
7.4.130.0090.01216.61
7.4.120.0100.00716.50
7.4.110.0070.01416.51
7.4.100.0100.01016.46
7.4.90.0170.00716.52
7.4.80.0100.00719.39
7.4.70.0090.01616.55
7.4.60.0120.00816.62
7.4.50.0000.00916.51
7.4.40.0090.00916.53
7.4.30.0100.00716.64
7.4.00.0030.01414.80
7.3.330.0020.00513.19
7.3.320.0180.00013.39
7.3.310.0000.00716.36
7.3.300.0000.00716.41
7.3.290.0070.00016.37
7.3.280.0090.00916.39
7.3.270.0110.01017.40
7.3.260.0120.00816.33
7.3.250.0080.01116.31
7.3.240.0110.00916.65
7.3.230.0090.01016.39
7.3.210.0130.01316.56
7.3.200.0060.01519.39
7.3.190.0140.00316.37
7.3.180.0160.00016.53
7.3.170.0120.00916.71
7.3.160.0070.01316.48
7.2.330.0090.00916.74
7.2.320.0070.01116.82
7.2.310.0180.00016.90
7.2.300.0090.00916.84
7.2.290.0090.00916.87
7.2.00.0030.01219.65
7.1.100.0000.01218.02
7.1.70.0040.00417.13
7.1.60.0150.00319.50
7.1.50.0150.00716.91
7.1.00.0030.07722.54
7.0.200.0120.00616.49
7.0.140.0000.07722.07
7.0.60.0100.07719.88
7.0.50.0070.08017.94
7.0.40.0070.09020.23
7.0.30.0230.08720.16
7.0.20.0170.07320.09
7.0.10.0230.05720.09
7.0.00.0130.08720.23
5.6.280.0000.07721.13
5.6.210.0100.08320.57
5.6.200.0070.03718.22
5.6.190.0130.08020.67
5.6.180.0200.04720.30
5.6.170.0300.07020.57
5.6.160.0070.04720.54
5.6.150.0100.03718.22
5.6.140.0100.08318.18
5.6.130.0100.08318.12
5.6.120.0100.06721.02
5.6.110.0200.07321.14
5.6.100.0130.03320.94
5.6.90.0070.08321.00
5.6.80.0030.05720.41
5.6.70.0030.08020.36
5.5.350.0100.05720.34
5.5.340.0000.04717.94
5.5.330.0100.08020.32
5.5.320.0030.04320.41
5.5.310.0370.06720.31
5.5.300.0030.07018.04
5.5.290.0070.08018.01
5.5.280.0130.07020.70
5.5.270.0100.03320.85
5.5.260.0070.08020.83
5.5.250.0130.07720.70
5.5.240.0100.04720.04
5.4.450.0900.07019.48
5.4.440.0030.06319.42
5.4.430.1030.06319.32
5.4.420.1030.06319.39
5.4.410.0100.05319.04
5.4.400.0530.05718.52
5.4.390.0300.05718.61
5.4.380.0330.05318.75
5.4.370.0330.05718.63
5.4.360.0330.05718.52
5.4.350.0500.07018.79
5.4.340.0330.06018.58
5.4.320.0300.06318.76
5.4.310.0370.05318.79
5.4.300.0330.05318.79
5.4.290.0230.07318.58
5.4.280.0400.05718.48
5.4.270.0470.04718.79
5.4.260.0400.05718.79
5.4.250.0230.06318.71
5.4.240.0400.05718.83
5.4.230.0430.05318.77
5.4.220.0500.06018.60
5.4.210.0430.04718.53
5.4.200.0430.04716.61
5.4.190.0370.05318.74
5.4.180.0400.07018.53
5.4.170.0270.09018.72
5.4.160.0400.05018.77
5.4.150.0400.05318.72
5.4.140.0330.05016.35
5.4.130.0330.05716.29
5.4.120.0400.06016.31
5.4.110.0370.05716.27
5.4.100.0300.05716.30
5.4.90.0270.06716.44
5.4.80.0330.05016.27
5.4.70.0300.05316.27
5.4.60.0300.05316.27
5.4.50.0300.05716.21
5.4.40.0370.07016.42
5.4.30.0230.05716.42
5.4.20.0300.05316.28
5.4.10.0430.05016.21
5.4.00.0430.04715.75
5.3.290.0430.07014.84
5.3.280.0370.06014.76
5.3.270.0500.06314.77
5.3.260.0330.07314.65
5.3.250.0400.05314.65
5.3.240.0300.06014.63
5.3.230.0300.06014.59
5.3.220.0300.06714.62
5.3.210.0370.07314.73
5.3.200.0330.05014.67
5.3.190.0370.04714.73
5.3.180.0400.05014.74
5.3.170.0330.05714.66
5.3.160.0400.04714.77
5.3.150.0430.07314.67
5.3.140.0300.05314.57
5.3.130.0500.04014.71
5.3.120.0300.06314.77
5.3.110.0300.05714.53
5.3.100.0500.06014.11
5.3.90.0330.06714.08
5.3.80.0270.05714.14
5.3.70.0330.05714.07
5.3.60.0330.05014.02
5.3.50.0270.05313.97
5.3.40.0370.05714.07
5.3.30.0400.06014.07
5.3.20.0370.05013.72
5.3.10.0270.06013.70
5.3.00.0370.05013.68
5.2.170.0330.03311.30
5.2.160.0270.04711.06
5.2.150.0200.05011.07
5.2.140.0230.04011.14
5.2.130.0300.03711.14
5.2.120.0170.05311.25
5.2.110.0400.04311.08
5.2.100.0270.05711.08
5.2.90.0170.05711.07
5.2.80.0300.03711.15
5.2.70.0300.06011.08
5.2.60.0270.04311.06
5.2.50.0230.05011.07
5.2.40.0230.04710.95
5.2.30.0200.04010.90
5.2.20.0270.03710.95
5.2.10.0230.04310.90
5.2.00.0230.04010.69
5.1.60.0230.0309.95
5.1.50.0200.03310.02
5.1.40.0170.03710.01
5.1.30.0200.04310.29
5.1.20.0170.04010.43
5.1.10.0230.04010.17
5.1.00.0200.03710.05
5.0.50.0100.0308.57
5.0.40.0130.0278.43
5.0.30.0130.0478.25
5.0.20.0100.0308.38
5.0.10.0170.0238.19
5.0.00.0130.0408.15
4.4.90.0100.0235.89
4.4.80.0100.0305.88
4.4.70.0230.0305.85
4.4.60.0130.0205.91
4.4.50.0130.0205.89
4.4.40.0100.0475.91
4.4.30.0100.0235.95
4.4.20.0130.0235.97
4.4.10.0100.0235.97
4.4.00.0070.0475.89
4.3.110.0070.0275.83
4.3.100.0070.0235.82
4.3.90.0100.0205.80
4.3.80.0070.0405.83
4.3.70.0130.0205.88
4.3.60.0070.0275.87
4.3.50.0130.0305.84
4.3.40.0100.0375.83
4.3.30.0030.0274.64
4.3.20.0070.0274.54
4.3.10.0070.0304.52
4.3.00.0100.0237.01

preferences:
59.1 ms | 400 KiB | 5 Q