Re: RFC: Allow throwing an exception as right part of null coalescing operator
| From: | Niklas Keller | Date: | Mon, 24 Jul 2017 09:54:05 +0000 |
| Subject: | Re: RFC: Allow throwing an exception as right part of null coalescing operator | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100030@lists.php.net to get a copy of this message | ||
>
> Dear internals,
>
> Don't you think allowing to throw an exception as the right side of null
> coalescing operator would be a good idea?
>
> Something like:
>
> echo $a ?? throw new \RuntimeException('foo');
>
> Regards,
> Tim
>
Sometimes that would be really helpful. What you can do is something like
that:
function raise(Throwable $t) {
throw $t;
}
$a = $a ?? raise(new \RuntimeException("foo"));
Regards, Niklas