3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ThrowsError { public $name = 'unnamed'; public function __construct($name) { $this->name = $name; throw new \Exception("I blew up the constructor of '$name'\n"); } } $emptyVar = null; $obj = (object)array('number' => 1); try { $emptyVar = new ThrowsError('emptyVar'); } catch (\Exception $e) { print($e->getMessage()); } try { $obj = new ThrowsError('obj'); } catch (\Exception $e) { print($e->getMessage()); } try { $notPreviouslyDefined = new ThrowsError('notPreviouslyDefined'); } catch (\Exception $e) { print($e->getMessage()); } var_dump($emptyVar); var_dump($obj); var_dump($notPreviouslyDefined);

preferences:
37.08 ms | 402 KiB | 5 Q