Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109308 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79721 invoked from network); 25 Mar 2020 20:39:33 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 25 Mar 2020 20:39:33 -0000 To: internals@lists.php.net References: <5BEF8264-4003-4056-A31C-FF8BEE85FED6@me.com> Date: Wed, 25 Mar 2020 20:04:17 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2 MIME-Version: 1.0 In-Reply-To: <5BEF8264-4003-4056-A31C-FF8BEE85FED6@me.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 46.59.72.204 Subject: Re: [RFC][DISCUSSION] throw expression From: ajf@ajf.me (Andrea Faulds) Message-ID: 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