Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107575 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43428 invoked from network); 18 Oct 2019 21:06:41 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Oct 2019 21:06:41 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 1C4112D204C for ; Fri, 18 Oct 2019 11:51:38 -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,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-yw1-xc36.google.com (mail-yw1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) (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 ; Fri, 18 Oct 2019 11:51:37 -0700 (PDT) Received: by mail-yw1-xc36.google.com with SMTP id i207so2518784ywc.9 for ; Fri, 18 Oct 2019 11:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=9OpHyZJhg0EjBRlpJsqZ9YEM+fw3XxLDT/gisXpAtcM=; b=MdRhpcwAbVD4mZ8+kedD63I7jqyIbOoLt8znRF8Pds4xwdtbR+9VSzPbr/560tNkvt ezfY7PEnrh3Z2/l5RJbUKvnnCmRP8HntQwZnlj3EVoQ+rDf+qbUaRSzi4xoUz+CRl7jR P1JyJHR7dcCpbhDJ6lMsk0LePk8goqjs2uQdGwa5m9eJsgA4pzXYTdVGg2cBBbIqDiYj 4GkUkfTsnUT1FnPHNCP27qkbu0GSgGM+4jZtOXv8VzmTpAzKUYQk6SA0a913BeyWazb6 2gbFcbP12FuDd5Ko9Ck2RpteXwVBCZ67WQ9yoF7EUBeCme028qujcwgfMn4qPxyrZ9RX wuPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=9OpHyZJhg0EjBRlpJsqZ9YEM+fw3XxLDT/gisXpAtcM=; b=sflMjnyq61Gscbit5B6FsorAvK467hPGpoInokU0LnW8AaIi2bi6LO0zdIfwWRedWl 62t6A7Jh5j8Ukr+brJcbyJUpR7aw1JmsFXvJmlEL9rFRzD7B3onPwa8Ry2LpZEyn8Xh9 W8utk6hOBPjCz2f3pNEBXFt//uproJuauLiyTdi1LMeHDhy3kQCcYzkKBM8QVGzGubYq Ol9Q2kv+nIrfnwdRG7IMTCYD/VGOOToS5TQsTcU4+8kkJFv+OGOThWhJCa/z+6qYfQxl BLWkHV0SdUFIBsVKYUaKkOKGfyleleP585dY8+LiitNTdHpOtTG8E1T4rcc/Fgv3kfNs jS5A== X-Gm-Message-State: APjAAAWKjLY6Nqnz9d2FN34/jxx483r6edliIsswmuTfDQXqon3V8OQW 6sruAO6JOCsAISCDvpDQ/wQkKyfUCDTLEQ== X-Google-Smtp-Source: APXvYqyzjEGvYDx7YZH17lq9omMYAciT1dTrHSKFnqS6f2ObVQlF2EnCN8VImD6842I/YbnjK+lxJw== X-Received: by 2002:a0d:df88:: with SMTP id i130mr8425482ywe.31.1571424696233; Fri, 18 Oct 2019 11:51:36 -0700 (PDT) Received: from ?IPv6:2601:c0:c67f:e34e:e967:8db7:ce56:c182? ([2601:c0:c67f:e34e:e967:8db7:ce56:c182]) by smtp.gmail.com with ESMTPSA id i134sm1536880ywa.9.2019.10.18.11.51.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Oct 2019 11:51:35 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_E5925F4A-B8D1-4AA9-9870-12C2294145D7" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Fri, 18 Oct 2019 14:51:34 -0400 In-Reply-To: Cc: PHP Internals To: Bishop Bettini References: <929062F1-E83F-4D81-B2C6-3916B744E101@newclarity.net> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] Adding explicit intent for SWITCH/CASE fall through? From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_E5925F4A-B8D1-4AA9-9870-12C2294145D7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 17, 2019, at 11:14 PM, Bishop Bettini wrote: >=20 > +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] (*). >=20 > That said, some questions: Hi Bishop, Thank you for the questions. > Do you envision this token accepting an optional argument, as break = does, to fall-through multiple nesting levels? Eg: No. I had not envisioned anything more than a single statement that = would indicate to PHP and other tools that a developer intends to _not_ = use a break.=20 What you suggest had not occurred to me, and is an interesting idea. But = I think I would prefer =E2=80=94 like Rowan Tommins argued =E2=80=94 = that we should keep it simple. =20 Being able to fallthrough many levels would be an extra feature we can = already accomplish in other, more explicit ways. I would rather focus on = targeting a use-case we cannot currently address, i.e. for PHP itself = and other tools to be able to flag lack of an explicit case exiting = action. > What do you envision the result of indicating fall-through to no = subsequent case? Eg: >=20 > switch ($x) { > case 1: fallthrough; > } > ?> Since it would have no effect that could be flagged or not flagged as a = warning. =20 It might be nice to allow it so that refactoring is less likely to = result in a warning. > Would a "pragma" (of sorts) be a part of the concept? >=20 > switch ($x) { > case 1: echo 'x1'; // ImplicitBreakError thrown here > case 2: echo 'x2'; > } > ?> Yes, but recent discussions on this list lamented the concern that we = could end up with tens if not hundreds of pragmas, and I concur that = would be no fun. =20 So how we would indicate is an open question PHP should answer before = adding a pragma for fallthrough. As an aside, I would be excited to see = that discussion start in earnest. Also, I am sure you remember that Nikita proposed an idea loosely = described as "Editions" and that might be the way to go. Imagine the = following: