3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on D7XpO

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.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