3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PreviousException extends \Exception {} class One extends \RuntimeException { // Just a standard exception } class Two extends \RuntimeException{ // An exception with custom constructor parameters public function __construct($customMessage, PreviousException $e) { parent::__construct($customMessage . "LOL", $e->getCode(), $e); } } try { throw new Two('Throwing two, but catch will receive a different class type', new One()); } catch (\Exception $e) { var_dump($e); }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Uncaught TypeError: Two::__construct(): Argument #2 ($e) must be of type PreviousException, One given, called in /in/a3ErJ on line 19 and defined in /in/a3ErJ:13 Stack trace: #0 /in/a3ErJ(19): Two->__construct('Throwing two, b...', Object(One)) #1 {main} thrown in /in/a3ErJ on line 13
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 2 passed to Two::__construct() must be an instance of PreviousException, instance of One given, called in /in/a3ErJ on line 19 and defined in /in/a3ErJ:13 Stack trace: #0 /in/a3ErJ(19): Two->__construct('Throwing two, b...', Object(One)) #1 {main} thrown in /in/a3ErJ on line 13
Process exited with code 255.
Output for 5.6.38
Catchable fatal error: Argument 2 passed to Two::__construct() must be an instance of PreviousException, instance of One given, called in /in/a3ErJ on line 19 and defined in /in/a3ErJ on line 13
Process exited with code 255.

preferences:
196.58 ms | 401 KiB | 212 Q