3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(ticks=1); function tick_handler() { echo "tick_handler()\n"; } 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, Exception $previous = null);tick_handler(); final private function __clone(); // Inhibits cloning of exceptions. final public function getMessage(); // message of exception final public function getCode(); // code of exception final public function getFile(); // source filename final public function getLine(); // source line final public function getTrace(); // an array of the backtrace() final public function getPrevious(); // previous exception final public function getTraceAsString(); // formatted string of trace // Overrideable public function __toString(); // formatted string for display }tick_handler(); /** * Define a custom exception class */ class MyException extends Exception {tick_handler(); // 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"; } } /** * Create a class to test the exception */ 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.0130.04719.07
5.4.190.0170.03719.23
5.4.180.0230.03018.86
5.4.170.0100.04319.21
5.4.160.0400.03319.16
5.4.150.0170.07019.07
5.4.140.0200.04016.33
5.4.130.0170.03716.33
5.4.120.0270.07016.38
5.4.110.0170.04716.19
5.4.100.0370.05316.42
5.4.90.0200.03716.51
5.4.80.0400.04016.23
5.4.70.0300.06316.50
5.4.60.0330.05716.56
5.4.50.0270.04316.33
5.4.40.0300.03716.42
5.4.30.0200.03716.23
5.4.20.0370.05016.55
5.4.10.0270.06316.42
5.4.00.0270.07015.91
5.3.270.0330.06314.72
5.3.260.0300.06714.75
5.3.250.0270.03714.69
5.3.240.0130.04714.53
5.3.230.0270.06714.68
5.3.220.0300.06714.59
5.3.210.0270.04314.59
5.3.200.0270.04314.59
5.3.190.0330.03014.59
5.3.180.0270.04714.68
5.3.170.0270.07014.54
5.3.160.0230.07014.56
5.3.150.0370.05314.64
5.3.140.0270.05714.46
5.3.130.0270.07014.60
5.3.120.0200.04014.60
5.3.110.0370.06314.55
5.3.100.0300.04014.01
5.3.90.0300.06714.25
5.3.80.0300.06313.93
5.3.70.0200.06714.02
5.3.60.0300.05713.90
5.3.50.0200.05313.86
5.3.40.0230.06013.86
5.3.30.0230.03714.14
5.3.20.0200.03713.67
5.3.10.0230.03713.89
5.3.00.0300.03013.56

preferences:
142.41 ms | 1386 KiB | 7 Q