Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107571 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34224 invoked from network); 18 Oct 2019 05:29:47 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Oct 2019 05:29:47 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id EB3F72D20A8 for ; Thu, 17 Oct 2019 20:14:35 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Thu, 17 Oct 2019 20:14:35 -0700 (PDT) Received: by mail-qt1-f179.google.com with SMTP id j31so7041029qta.5 for ; Thu, 17 Oct 2019 20:14:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=ykE5EGn/i3wJT1lwHrgPTC/oilljfGTt4ohcefas/Bs=; b=aYrjOGr6blhVSeCOZBj6QrhTvzl00fhx31imBK43qVTrh+12tzckYhc4NzWU8fWtke chTifpBPTOogOGe6EXrQuwICkjZGjnq1M7XEvIsVx0oBIhoMcnoV44KHJKIrhFhmYnHo IZu/bywD4gGoMVYLt2H7ZO8iBHJwfi+J5ijFkyXuuvn5uLqueUXMQOhnMKi78oy27aZ2 OOl47yUj3LNZAd5tXRlRG5bpy3ZLl/Lg2OMgEZAaEuI1AGmiEfBnWv6sNJfJOuRgxEmu py6mrvzJ7QYK/TK1ChIps6tbs4WBX9rzgZWe68/EudF/1cEY/2YTDHZh6WqSxKvyrcqL RgLQ== X-Gm-Message-State: APjAAAUV7i7RZinQYfC9c5634ZNl6QjCPcKh9KaN1gEGzxyEJq1CMU9c K5Y+WvarAgVWLryol0TtnoJ9tR5Z7pNaUhK9q+g9oDqB/RU= X-Google-Smtp-Source: APXvYqzSnM10OVCsps3XYikpEOthY+QZ1FrAH0rojeTjdGVeTgYuiaNxUBAHJFsQ+ZWL/zeetgUB5fsC8srciEjR4Hs= X-Received: by 2002:aed:26c2:: with SMTP id q60mr1293839qtd.15.1571368474677; Thu, 17 Oct 2019 20:14:34 -0700 (PDT) MIME-Version: 1.0 References: <929062F1-E83F-4D81-B2C6-3916B744E101@newclarity.net> In-Reply-To: <929062F1-E83F-4D81-B2C6-3916B744E101@newclarity.net> Reply-To: bishop@php.net Date: Thu, 17 Oct 2019 23:14:09 -0400 Message-ID: To: Mike Schinkel Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000be974a059526bb1d" X-Envelope-From: Subject: Re: [PHP-DEV] Adding explicit intent for SWITCH/CASE fall through? From: bishop@php.net (Bishop Bettini) --000000000000be974a059526bb1d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Oct 17, 2019 at 4:54 PM Mike Schinkel wrote: > Before creating an RFC I wanted to get reactions to the idea of adding > FALLTHROUGH option to SWITCH/CASE for when the developer explicitly want > logic to fall through to the next case and does not want to use a BREAK. > > My simples motivation for this feature is that my IDE (PhpStorm) always > flags CASE statements w/o BREAKs because it cannot know when I intend for > the logic to fallthrough and not break. If there was an optional > FALLTHROUGH then my IDE could flag any CASE statements that do not have a > FALLTHROUGH or BREAK =E2=80=94 which would indicate an error of my intent= =E2=80=94 and > avoid flagging all the situations where I intentionally want it to fall > through. > > Beyond that, this might also be useful for other static analysis tools > such as PhpStan. > Ust > Additionally it could be added in 8.0 and then in 8.1 flagged with a > warning when a CASE does not have one for the two, but only if people don= 't > object to this. While I know some on this list feel strongly that warning= s > must come with to future plans to generate errors I would personally be > 100% okay if it indefinitely generated only a warning. > > In summary I want a mechanism to be allow me to explicitly indicate my > intent with respect to SELECT/CASE statements. What do you think? Is thi= s > worthy of an RFC, or is there some reason a majority would object to such > an addition? > +1. It's 100% opt-in. People can keep using implicit fall-through, their own /* fallthrough */ comments, or the new token. There's virtually no overhead in the compile phase and it doesn't mess with the jump table optimizations. There's precedent for this desire in PHP static analyzers [1] as well as other major projects: eg, the Linux Foundation just completed a 2 year project to remove implicit fall-through in the Linux kernel [2] (*). That said, some questions: Do you envision this token accepting an optional argument, as break does, to fall-through multiple nesting levels? Eg: What do you envision the result of indicating fall-through to no subsequent case? Eg: Would a "pragma" (of sorts) be a part of the concept? [1]:https://github.com/phan/phan/issues/2550 [2]:https://lwn.net/Articles/794944/ (*) Fun trivia: PHP is mentioned in that LWN article about naming conventions. --000000000000be974a059526bb1d--