3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CustomException extends Exception { public $object; public function __construct(string $msg, SomeClass $object) { $this->object = $object; parent::__construct($msg); } } class SomeClass { public function __construct() { throw new CustomException("Invalid parameters!", $this); } } try { $a = new SomeClass(); } catch (CustomException $e) { $a = $e->object; } var_dump($a);

preferences:
27.09 ms | 404 KiB | 5 Q