3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Exception { protected $message = 'Unknown exception'; // exception message private $string; // __toString cache protected $code = 0; // user defined exception code protected $file; // source filename of exception protected $line; // source line of exception private $trace; // backtrace private $previous; // previous exception if nested exception public function __construct(){ $message = null; $code = 0; self::$previous = null;} } // Overrideable class MyException extends Exception{ public function __construct($message, $code = 0, Exception $previous = null) { // some code // make sure everything is assigned properly parent::__construct($message, $code, $previous); } // custom string representation of object public function __toString() { return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; } public function customFunction() { echo "A custom function for this type of exception\n"; } } class TestException { public $var; const THROW_NONE = 0; const THROW_CUSTOM = 1; const THROW_DEFAULT = 2; function __construct($avalue = self::THROW_NONE) { switch ($avalue) { case self::THROW_CUSTOM: // throw custom exception throw new MyException('1 is an invalid parameter', 5); break; case self::THROW_DEFAULT: // throw default one. throw new Exception('2 is not allowed as a parameter', 6); break; default: // No exception, object will be created. $this->var = $avalue; break; } } } try { $o = new TestException(TestException::THROW_CUSTOM); } catch (MyException $e) { // Will be caught echo "Caught my exception\n", $e; $e->customFunction(); } catch (Exception $e) { // Skipped echo "Caught Default Exception\n", $e; } // Continue execution var_dump($o); // Null echo "\n\n"; // Example 2 try { $o = new TestException(TestException::THROW_DEFAULT); } catch (MyException $e) { // Doesn't match this type echo "Caught my exception\n", $e; $e->customFunction(); } catch (Exception $e) { // Will be caught echo "Caught Default Exception\n", $e; } // Continue execution var_dump($o); // Null echo "\n\n"; try { $o = new TestException(TestException::THROW_CUSTOM); } catch (Exception $e) { // Will be caught echo "Default Exception caught\n", $e; } // Continue execution var_dump($o); // Null echo "\n\n"; try { $o = new TestException(); } catch (Exception $e) { // Skipped, no exception echo "Default Exception caught\n", $e; } // Continue execution var_dump($o); // TestException echo "p\n\n"; ?>

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.40.0070.00718.85
8.3.30.0070.00718.77
8.3.20.0000.00820.24
8.3.10.0050.00323.66
8.3.00.0070.00020.77
8.2.170.0000.01422.96
8.2.160.0100.00720.35
8.2.150.0030.00524.18
8.2.140.0050.00324.66
8.2.130.0040.01126.16
8.2.120.0040.00422.12
8.2.110.0060.00322.25
8.2.100.0040.00717.78
8.2.90.0040.00419.30
8.2.80.0000.00917.97
8.2.70.0100.00017.50
8.2.60.0030.00617.91
8.2.50.0040.00418.07
8.2.40.0030.00618.22
8.2.30.0000.00917.95
8.2.20.0080.00017.77
8.2.10.0000.00817.70
8.2.00.0080.00017.77
8.1.270.0060.00923.89
8.1.260.0040.00426.35
8.1.250.0030.00628.09
8.1.240.0060.00323.91
8.1.230.0070.00419.16
8.1.220.0030.00617.74
8.1.210.0000.00818.77
8.1.200.0030.00617.35
8.1.190.0000.00817.39
8.1.180.0000.00918.10
8.1.170.0070.00318.21
8.1.160.0000.00722.10
8.1.150.0040.00418.53
8.1.140.0070.00017.35
8.1.130.0000.00717.81
8.1.120.0040.00417.37
8.1.110.0040.00417.43
8.1.100.0040.00417.32
8.1.90.0060.00317.44
8.1.80.0030.00317.45
8.1.70.0030.00317.33
8.1.60.0040.00417.55
8.1.50.0040.00417.46
8.1.40.0060.00317.35
8.1.30.0040.00417.49
8.1.20.0040.00417.54
8.1.10.0000.00717.30
8.1.00.0040.00417.30
8.0.300.0040.00418.77
8.0.290.0070.00017.18
8.0.280.0050.00318.30
8.0.270.0000.00717.18
8.0.260.0050.00316.80
8.0.250.0030.00316.92
8.0.240.0040.00416.98
8.0.230.0000.00816.96
8.0.220.0040.00416.90
8.0.210.0070.00016.92
8.0.200.0030.00316.86
8.0.190.0040.00416.87
8.0.180.0000.00716.97
8.0.170.0040.00416.92
8.0.160.0030.00416.82
8.0.150.0040.00416.90
8.0.140.0000.00916.89
8.0.130.0080.00013.33
8.0.120.0050.00316.79
8.0.110.0020.00516.80
8.0.100.0070.00016.82
8.0.90.0080.00017.00
8.0.80.0110.00716.99
8.0.70.0000.00716.98
8.0.60.0050.00217.05
8.0.50.0000.00716.80
8.0.30.0080.01017.10
8.0.20.0100.01517.40
8.0.10.0040.00417.18
8.0.00.0070.01016.78
7.4.330.0000.00515.02
7.4.320.0000.00616.58
7.4.300.0070.00016.63
7.4.290.0000.00716.63
7.4.280.0080.00016.49
7.4.270.0080.00016.64
7.4.260.0030.00516.34
7.4.250.0040.00416.36
7.4.240.0030.00416.43
7.4.230.0000.00716.58
7.4.220.0090.00616.59
7.4.210.0060.00816.55
7.4.200.0030.00316.49
7.4.190.0030.00316.72
7.4.160.0110.00716.48
7.4.150.0100.00717.40
7.4.140.0060.01217.86
7.4.130.0080.00916.42
7.4.120.0130.00516.53
7.4.110.0050.01116.64
7.4.100.0070.01016.55
7.4.90.0080.00816.43
7.4.80.0130.00719.39
7.4.70.0040.01216.43
7.4.60.0130.00316.57
7.4.50.0000.00416.59
7.4.40.0090.00622.77
7.4.30.0080.00816.72
7.4.00.0050.01215.00
7.3.330.0050.00013.08
7.3.320.0000.00713.25
7.3.310.0050.00216.20
7.3.300.0040.00416.35
7.3.290.0100.00716.34
7.3.280.0090.01016.31
7.3.270.0120.00617.40
7.3.260.0180.00016.36
7.3.250.0130.00516.42
7.3.240.0110.00716.57
7.3.230.0120.00616.44
7.3.210.0130.00516.57
7.3.200.0000.01819.39
7.3.190.0130.00316.48
7.3.180.0110.00516.35
7.3.170.0150.00016.51
7.3.160.0090.00616.37
7.3.120.0080.00714.57
7.3.110.0100.00714.65
7.3.100.0030.01014.57
7.3.90.0060.00314.84
7.3.80.0100.00314.99
7.3.70.0100.00614.96
7.3.60.0110.00314.56
7.3.50.0000.01514.89
7.3.40.0070.01014.88
7.3.30.0100.00314.84
7.3.20.0130.00316.63
7.3.10.0110.00316.46
7.3.00.0080.00416.63
7.2.330.0170.00016.57
7.2.320.0000.01816.68
7.2.310.0110.00716.56
7.2.300.0140.00416.49
7.2.290.0080.00916.62
7.2.250.0070.01314.91
7.2.240.0070.01415.01
7.2.230.0060.00914.98
7.2.220.0050.00515.20
7.2.210.0000.01614.73
7.2.200.0120.00615.06
7.2.190.0030.01114.80
7.2.180.0100.00714.89
7.2.170.0040.01114.95
7.2.60.0030.01416.59
7.2.00.0070.01019.28
7.1.330.0060.01015.52
7.1.320.0060.00315.45
7.1.310.0070.00715.45
7.1.300.0040.00915.61
7.1.290.0060.00315.48
7.1.280.0070.00715.77
7.1.270.0040.00715.59
7.1.260.0040.00715.67
7.1.200.0030.01215.58
7.1.70.0060.00916.99
7.1.60.0000.01117.18
7.1.50.0070.01016.77
7.1.00.0070.07322.48
7.0.200.0080.00816.39
7.0.140.0030.06722.00
7.0.80.0200.04019.98
7.0.70.0270.04019.90
7.0.60.0300.03720.05
7.0.50.0400.03020.31
7.0.40.0100.03720.08
7.0.30.0030.04320.07
7.0.20.0070.05320.12
7.0.10.0100.06320.14
7.0.00.0000.04020.12
5.6.280.0030.07320.93
5.6.230.0030.04720.53
5.6.220.0030.04320.64
5.6.210.0000.04320.59
5.6.200.0030.04721.11
5.6.190.0070.03721.09
5.6.180.0000.04321.13
5.6.170.0070.04021.06
5.6.160.0100.06321.07
5.6.150.0030.03721.10
5.6.140.0000.04321.04
5.6.130.0130.03321.20
5.6.120.0100.08021.04
5.6.110.0230.05321.06
5.6.100.0130.07721.07
5.6.90.0070.04721.12
5.6.80.0030.07720.58
5.6.70.0100.06720.36
5.6.60.0030.08020.43
5.6.50.0000.09020.49
5.6.40.0000.05320.40
5.6.30.0100.07720.41
5.6.20.0070.07720.46
5.6.10.0230.06720.39
5.6.00.0230.06020.45
5.5.370.0000.04320.52
5.5.360.0100.03720.39
5.5.350.0100.03320.46
5.5.340.0030.03720.89
5.5.330.0000.04320.80
5.5.320.0030.05020.89
5.5.310.0030.05020.93
5.5.300.0100.07320.88
5.5.290.0100.03720.91
5.5.280.0070.08020.80
5.5.270.0100.05020.95
5.5.260.0200.06320.89
5.5.250.0100.06320.70
5.5.240.0170.07720.33
5.5.230.0200.06720.17
5.5.220.0100.07020.29
5.5.210.0100.07720.28
5.5.200.0030.08020.25
5.5.190.0070.06020.16
5.5.180.0030.07320.02
5.5.160.0130.07020.14
5.5.150.0100.05720.23
5.5.140.0000.08720.17
5.5.130.0070.08020.20
5.5.120.0100.08320.24
5.5.110.0130.08020.22
5.5.100.0100.03720.13
5.5.90.0070.08020.18
5.5.80.0130.07020.09
5.5.70.0070.07719.97
5.5.60.0100.07320.18
5.5.50.0000.04320.11
5.5.40.0030.07719.99
5.5.30.0100.07320.10
5.5.20.0000.08720.11
5.5.10.0100.07720.00
5.5.00.0030.07320.11
5.4.450.0100.03019.36
5.4.440.0030.06319.45
5.4.430.0100.08019.23
5.4.420.0070.05019.23
5.4.410.0130.07319.32
5.4.400.0130.07319.13
5.4.390.0100.08019.12
5.4.380.0170.06719.03
5.4.370.0130.07319.18
5.4.360.0070.08019.04
5.4.350.0130.07019.03
5.4.340.0170.06319.03
5.4.320.0030.04718.95
5.4.310.0100.07019.13
5.4.300.0030.08019.03
5.4.290.0100.07719.18
5.4.280.0030.07318.87
5.4.270.0070.08319.12
5.4.260.0030.05718.84
5.4.250.0130.07019.11
5.4.240.0000.06318.89
5.4.230.0070.06319.04
5.4.220.0070.08019.02
5.4.210.0000.05719.20
5.4.200.0030.06019.20
5.4.190.0100.04319.17
5.4.180.0130.04719.11
5.4.170.0000.05319.02
5.4.160.0070.07319.02
5.4.150.0100.06319.16
5.4.140.0130.06716.49
5.4.130.0000.05716.46
5.4.120.0130.06316.24
5.4.110.0000.07716.49
5.4.100.0070.07316.38
5.4.90.0130.06316.55
5.4.80.0100.07316.52
5.4.70.0200.06016.45
5.4.60.0200.05316.49
5.4.50.0130.06316.40
5.4.40.0100.05016.49
5.4.30.0170.06716.48
5.4.20.0030.05016.31
5.4.10.0070.07016.34
5.4.00.0000.07015.86
5.3.290.0030.08014.68
5.3.280.0100.07314.61
5.3.270.0070.07014.64
5.3.260.0030.08714.57
5.3.250.0100.07314.75
5.3.240.0070.07314.73
5.3.230.0000.05014.64
5.3.220.0170.06014.60
5.3.210.0070.06014.61
5.3.200.0130.06314.71
5.3.190.0070.04314.56
5.3.180.0130.07014.61
5.3.170.0000.06014.59
5.3.160.0000.07714.57
5.3.150.0030.08314.69
5.3.140.0100.03714.58
5.3.130.0170.06014.71
5.3.120.0030.07714.70
5.3.110.0070.06714.52
5.3.100.0130.07014.22
5.3.90.0100.05014.00
5.3.80.0070.05014.14
5.3.70.0030.04314.19
5.3.60.0030.03714.12
5.3.50.0070.07713.96
5.3.40.0030.07713.88
5.3.30.0030.07013.96
5.3.20.0070.04713.73
5.3.10.0100.06313.59
5.3.00.0070.07313.67
5.2.170.0070.06711.73
5.2.160.0070.06011.73
5.2.150.0130.05011.73
5.2.140.0070.02711.73
5.2.130.0100.05711.73
5.2.120.0030.05011.73
5.2.110.0030.06711.73
5.2.100.0070.04711.73
5.2.90.0030.06011.73
5.2.80.0030.05011.73
5.2.70.0130.04311.73
5.2.60.0170.05311.73
5.2.50.0030.06711.73
5.2.40.0130.05011.73
5.2.30.0130.04311.73
5.2.20.0070.06311.73
5.2.10.0030.03311.73
5.2.00.0030.06311.73
5.1.60.0100.04711.73
5.1.50.0030.04311.73
5.1.40.0030.05011.73
5.1.30.0070.04011.73
5.1.20.0100.04711.73
5.1.10.0030.05311.73
5.1.00.0030.05711.73
5.0.50.0030.03311.73
5.0.40.0000.04711.73
5.0.30.0030.04711.73
5.0.20.0070.04311.73
5.0.10.0000.03311.73
5.0.00.0030.06311.73
4.4.90.0000.03711.73
4.4.80.0030.02711.73
4.4.70.0100.02311.73
4.4.60.0000.03711.73
4.4.50.0000.03711.73
4.4.40.0030.05311.73
4.4.30.0000.02711.73
4.4.20.0070.03311.73
4.4.10.0070.02011.73
4.4.00.0000.05711.73
4.3.110.0030.03311.73
4.3.100.0000.03711.73
4.3.90.0000.02311.73
4.3.80.0000.05711.73
4.3.70.0070.02711.73
4.3.60.0000.04011.73
4.3.50.0000.03711.73
4.3.40.0030.04311.73
4.3.30.0070.01311.73
4.3.20.0030.02311.73
4.3.10.0070.02011.73
4.3.00.0000.03311.73

preferences:
39.33 ms | 400 KiB | 5 Q