3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class NewException extends Exception { //$message is now not optional, just for the extension. public function __construct($message, $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); } } /** * TestException * Tests and throws Exceptions. */ class TestException { const NONE = 0; const NORMAL = 1; const CUSTOM = 2; public function __construct($type = self::NONE) { switch ($type) { case 1: throw new Exception('Normal Exception'); break; case 2: throw new NewException('Custom Exception'); break; default: return 0; //No exception is thrown. } } } try { $t = new TestException(TestException::CUSTOM); } catch (Exception $e) { print_r($e); //Exception Caught } ?>
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
NewException Object ( [message:protected] => Custom Exception [string:Exception:private] => [code:protected] => 0 [file:protected] => /in/8pM0h [line:protected] => 24 [trace:Exception:private] => Array ( [0] => Array ( [file] => /in/8pM0h [line] => 33 [function] => __construct [class] => TestException [type] => -> [args] => Array ( [0] => 2 ) ) ) [previous:Exception:private] => )
Output for 5.1.2 - 5.2.17
Fatal error: Wrong parameters for Exception([string $exception [, long $code ]]) in /in/8pM0h on line 6
Process exited with code 255.
Output for 5.1.0 - 5.1.1
Fatal error: Wrong parameter count for exception([string $exception [, long $code ]]) in /in/8pM0h on line 6
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Argument 3 must not be null in /in/8pM0h on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/8pM0h on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/8pM0h on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/8pM0h on line 5
Process exited with code 255.