Hey Ilija,
Ilija Tovilo wrote:
Hi everybody! I hope you’re doing well.
Due to the modest feedback I’d like to move the throw expression RFC to “under
discussion”.
https://wiki.php.net/rfc/throw_expression
In short, the RFC proposes to convert the throw statement into an expression to
make it usable in arrow functions, the coalesce operator, as well as the
ternary/elvis operator.
Thanks for this RFC, I have wanted this sometimes when writing PHP code.
The ?? operator is one of those places, but I am surprised you haven't
mentioned the `and` and `or` operators.
It is classic PHP style (probably borrowed from Perl?) to write e.g.:
$mysql = mysql_open(...) or die("Couldn't connect to MySQL");
Obviously not very modern with use of mysql_ ;)
But the `or` operator is still quite handy for this kind of trivial
error handling, and it would be great to be able to write e.g.:
$fp = @fopen($filename, "r") or throw new Exception("Couldn't open
file!");
Likewise for `and` (I think it is less common):
$somethingWentWrong and throw new Exception("Oh no!");
So I would be happy to see `throw` become an expression for these
reasons, even if it is a bit conceptually weird given it never returns
anything!
Thanks,
Andrea
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php