Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109310 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83132 invoked from network); 25 Mar 2020 20:47:27 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 25 Mar 2020 20:47:27 -0000 To: internals@lists.php.net References: <5BEF8264-4003-4056-A31C-FF8BEE85FED6@me.com> Date: Wed, 25 Mar 2020 20:12:11 +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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 46.59.72.204 Subject: Re: [PHP-DEV] [RFC][DISCUSSION] throw expression From: ajf@ajf.me (Andrea Faulds) Message-ID: Hi Dan, Dan Ackroyd wrote: > Regarding the example: > > $condition || throw new Exception('$condition must be truthy') > && $condition2 || throw new Exception('$condition2 must be truthy'); > > The "Deprecate left-associative ternary operator"* RFC made it so that > parentheses are required when ternary operators are nested in > complicated statements. > > Would a similar requirement for parentheses around complicated throw > expressions be a suitable solution to avoid people being surprised by > the behaviour? > > cheers > Dan > Ack > > * https://wiki.php.net/rfc/ternary_associativity > Is there a strong reason to require parentheses? I would think we can just give `throw` an appropriate precedence so that expressions like the above do what is desired — and then if you wanted to do something unusual, you would have to add parentheses anyway. Regards, Andrea