Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109331 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93436 invoked from network); 26 Mar 2020 13:40:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Mar 2020 13:40:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0ADD01804D0 for ; Thu, 26 Mar 2020 05:04:59 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, MALFORMED_FREEMAIL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS714 17.58.32.0/20 X-Spam-Virus: No X-Envelope-From: Received: from ms11p00im-qufo17281501.me.com (ms11p00im-qufo17281501.me.com [17.58.38.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 26 Mar 2020 05:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1585224295; bh=pAQ3FhQeDYAVsOP2Xf9xlzWn90W0XA0m+x/J6nojFqc=; h=Date:Subject:From:To:Message-ID:Content-type; b=2AFOB+sljf1yvKEE4nVpNzUeTrabRAhEBgPkY34R1K9iOrg4urjruljR4QTY0o5c8 +Q+kIY/htlTjQIbLwbbJcRo9nt+Raz0ryFoHtvSUte8KK7yoUBaBQKO69sb5KIj/Y8 G5jWQkyjbKv27mVO9mKCZfd58P1E9hP1weaZ1NRmXfgJVjbvNtsQyZeUHbABOZzJxP 6mCNbF37Jrt84Djb+Xz95FqlTzZQkbvBwuWjHQwGNjgXSvWfsFXrYlZXNO/fZqtC7I 2zoCQZziYA6lC/SFfQZKS/MC+f4hxb0M05CjLw5yRl6Ghn6vBS/wBGqvLhaZlwtuwT rZTqNcTjn+iaQ== Received: from [192.168.1.106] (9.66.194.178.dynamic.wline.res.cust.swisscom.ch [178.194.66.9]) by ms11p00im-qufo17281501.me.com (Postfix) with ESMTPSA id 0EC10B4033C for ; Thu, 26 Mar 2020 12:04:54 +0000 (UTC) User-Agent: Microsoft-MacOutlook/16.35.20030802 Date: Thu, 26 Mar 2020 13:04:49 +0100 To: PHP internals Message-ID: <0CA9AC56-EFF7-4F72-90E0-AA0FF13B115A@me.com> Thread-Topic: [PHP-DEV] [RFC][DISCUSSION] throw expression References: <5BEF8264-4003-4056-A31C-FF8BEE85FED6@me.com> In-Reply-To: Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: 7bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2020-03-26_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=671 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-2003260092 Subject: Re: [PHP-DEV] [RFC][DISCUSSION] throw expression From: ilija.tovilo@me.com (Ilija Tovilo) On 22.03.20, 18:17, "Dan Ackroyd" wrote: > $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? I've thought about this some more. There is a reasonable way to recognize this, namely to check if the expression after the throw keyword is of type ZEND_AST_OR or ZEND_AST_AND. The expression above will fail with this message (given that $condition is false): ``` Fatal error: Uncaught Error: Can only throw objects in ... ``` IMO this is clear enough that a message for this edge case is not necessary.