3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Exception { protected $message = 'Unknown exception'; private $string; protected $code = 0; protected $file; protected $line; private $trace; private $previous; function __construct($message = null, $code = 0, Exceptio $previous = null) final public string getMessage ( void ); final public Exception getPrevious ( void ); final public mixed getCode ( void ); final public string getFile ( void ); final public int getLine ( void ); final public array getTrace ( void ); final public string getTraceAsString ( void ); public string __toString ( void ); final private void __clone ( void ); } /** * Define a custom exception class */ class MyException extends Exception { // Redefine the exception so message isn't optional 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; } } } // Example 1 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"; // Example 3 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"; // Example 4 try { $o = new TestException(); } catch (Exception $e) { // Skipped, no exception echo "Default Exception caught\n", $e; } // Continue execution var_dump($o); // TestException echo "\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)
5.4.200.0060.03612.38
5.4.190.0060.04212.38
5.4.180.0150.04912.38
5.4.170.0090.03912.38
5.4.160.0140.03512.38
5.4.150.0120.03912.37
5.4.140.0110.03812.06
5.4.130.0090.04212.04
5.4.120.0120.03612.01
5.4.110.0110.03712.00
5.4.100.0080.04112.01
5.4.90.0150.05012.01
5.4.80.0100.03912.01
5.4.70.0100.03812.00
5.4.60.0100.03812.01
5.4.50.0120.03812.01
5.4.40.0100.04011.99
5.4.30.0130.03611.99
5.4.20.0120.03611.98
5.4.10.0090.03911.98
5.4.00.0110.03911.48
5.3.270.0210.06112.72
5.3.260.0090.04312.72
5.3.250.0100.04312.72
5.3.240.0100.04112.72
5.3.230.0070.04512.71
5.3.220.0130.03812.68
5.3.210.0070.04512.68
5.3.200.0100.04012.68
5.3.190.0100.04212.67
5.3.180.0140.05112.67
5.3.170.0100.04112.67
5.3.160.0120.03912.68
5.3.150.0120.03812.67
5.3.140.0100.04012.66
5.3.130.0100.04212.66
5.3.120.0090.04212.66
5.3.110.0130.03912.65
5.3.100.0110.03912.12
5.3.90.0110.03912.08
5.3.80.0180.04912.08
5.3.70.0110.04012.07
5.3.60.0110.03912.06
5.3.50.0100.03912.00
5.3.40.0110.03912.00
5.3.30.0130.03711.96
5.3.20.0070.04411.74
5.3.10.0180.05311.70
5.3.00.0110.04611.68
5.2.170.0120.0349.20
5.2.160.0120.0309.20
5.2.150.0110.0319.19
5.2.140.0090.0349.19
5.2.130.0090.0319.15
5.2.120.0110.0339.15
5.2.110.0100.0309.16
5.2.100.0100.0309.15
5.2.90.0080.0329.15
5.2.80.0130.0439.14
5.2.70.0090.0329.14
5.2.60.0080.0329.10
5.2.50.0080.0379.07
5.2.40.0120.0299.04
5.2.30.0060.0399.01
5.2.20.0120.0389.01
5.2.10.0090.0398.92
5.2.00.0100.0328.77
5.1.60.0090.0278.06
5.1.50.0070.0278.06
5.1.40.0090.0258.05
5.1.30.0070.0288.39
5.1.20.0080.0298.42
5.1.10.0150.0528.14
5.1.00.0050.0298.14
5.0.50.0030.0256.62
5.0.40.0060.0216.47
5.0.30.0050.0346.29
5.0.20.0050.0236.26
5.0.10.0070.0216.23
5.0.00.0050.0346.22
4.4.90.0050.0154.78
4.4.80.0050.0164.76
4.4.70.0040.0184.75
4.4.60.0050.0184.76
4.4.50.0040.0164.77
4.4.40.0050.0274.71
4.4.30.0040.0184.76
4.4.20.0050.0164.84
4.4.10.0050.0164.85
4.4.00.0050.0274.76
4.3.110.0040.0184.67
4.3.100.0050.0154.67
4.3.90.0050.0144.63
4.3.80.0040.0264.58
4.3.70.0050.0144.63
4.3.60.0040.0154.63
4.3.50.0040.0184.63
4.3.40.0040.0254.54
4.3.30.0050.0323.30
4.3.20.0030.0183.28
4.3.10.0040.0163.23
4.3.00.0000.01313.22

preferences:
142.17 ms | 1386 KiB | 7 Q