Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107570 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87089 invoked from network); 18 Oct 2019 00:22:43 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Oct 2019 00:22:43 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 6F1042D20FB for ; Thu, 17 Oct 2019 15:07:27 -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,URIBL_BLOCKED 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-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) (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 15:07:26 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id 206so1200466ybc.8 for ; Thu, 17 Oct 2019 15:07:26 -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=Du3VH9/tYELqAMJDmaWd8Ayqk93eLZ6dswWm17cjt74=; b=r0U6yCp9RHodkeJYTYALRJCeTVAgJ6dUsh+K+tOH96RndKhuSmfwBRFILTg3eoT82k EBEhlKa+znKPepZI6+kfz5lM7FYwZIjeNcTh5eprqzGSl+t2ffUGpwn1+P4NrDw7HnJS HBc7Ax+XjAvcIxV48IVyyhvOF/rv7AGK/WyLkUDdK34qjytRYOtqvj66n2O37Ep5r2fU Plp20QsfSpGKsJi6eue1rRd26jBVUH430t345n1O5w1p+0V7BvUlQMbAoREggpw28KQg PZBXGWOeJjHKMAvwf6j585LSP8XmnFoVqQO6iLEAlVfoUNUEaaf+y5Xw6sb0rLvLh8pW k7RA== 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=Du3VH9/tYELqAMJDmaWd8Ayqk93eLZ6dswWm17cjt74=; b=DYTQiZH46ki5CgbA9TEyDkXeHwIKMBu/9Ch0TNZHJ58ypRnA2Vv/28/Qm+6YKjeBc2 2Qz53bACHPK5OnhCXD3UfjY5e3omyGK5ulKLVLy96q/9hK+c7Ir7GxSs3gfjM1qaU9aq PA1jhXhH4CqL1hyf+cyfKluB2sYn21BgxiImRPIvsm34oJlLJcekKZ8F7C09ZLGVWa49 NohoRaRjQKQNk6YpvmQ1SEQBqIK0CTlUg13Dig5P5KJI56jqFTiNLU6Ie/OpdX+yEduf XVikYqK3RZRCf1EDFKwUzLTogV+ZRuZ6TKd6zjP7lDALVS1H2/r18udsggVoBhI4cjCu lJSw== X-Gm-Message-State: APjAAAXCoSVUUffXSYCKsQ+ml5mbY/7WG0l1njewLNuvbCUNjnCBffFg gO0zPN3Zow48JSQ7t70kLvlE9A== X-Google-Smtp-Source: APXvYqySmVYeg2fiWj/sTislISjRpUjcUHtaqax2U9yoTcxbX6b+z1+nZ3PpkJui27yMhxsWI2+sZg== X-Received: by 2002:a25:8a:: with SMTP id 132mr3804987yba.246.1571350046125; Thu, 17 Oct 2019 15:07:26 -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 r14sm1112364ywl.97.2019.10.17.15.07.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Oct 2019 15:07:23 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_A941E84F-90FB-476F-ACE2-5C6ED6D62B30" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Thu, 17 Oct 2019 18:07:22 -0400 In-Reply-To: <5da8e051.1c69fb81.b05ef.ef7dSMTPIN_ADDED_MISSING@mx.google.com> Cc: internals@lists.php.net To: Mark Randall References: <929062F1-E83F-4D81-B2C6-3916B744E101@newclarity.net> <5da8e051.1c69fb81.b05ef.ef7dSMTPIN_ADDED_MISSING@mx.google.com> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] Re: Adding explicit intent for SWITCH/CASE fall through? From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_A941E84F-90FB-476F-ACE2-5C6ED6D62B30 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 At the case level, not the switch level. Here is the code that I was working on that caused me to finally send = this message. switch ( $new_name ) { case 'portal_id': case 'portalid': $new_name =3D 'portalId'; break; case 'form_id': case 'formid': $new_name =3D 'formId'; break; case 'educationtype':=20 $update =3D false; fallthrough; case 'education': $new_name =3D 'educationType'; if ( EducationTypes::is_edu_type_slug( $value ) ) { $new_value =3D EducationTypes\Names::get( $value ); } break; default: $update =3D false; break; } (Note the code is from an iterative refactoring process where I will = eventually get rid of this specific code but in the short term I am = trying to unify all the terms into a single list rather than have a = bunch of different names in the code for the same thing. When iterative = refactoring my emphasis is understanding the logic and on on unifying = the code and not on what is the best architecture.) > It sounds like a job for a static analysis comment: >=20 > /** @DisableSwitchStatementFallthroughWarning */ Interesting. That feels more like static analysis tools use the only = tool they have =E2=80=94 comments =E2=80=94 since they can't change PHP, = and not a good model for language evolution. My reaction is it feels rather inelegant. It would be a heck of a lot = more to type and a good bit harder to read. In my perfect world it = would be part of the language, not just a commenting convention.=20 Is there a a standardized list of these for PHP somewhere on php.net? I = googled and did not find any such list; maybe I am missing it?=20 I doubt we would want an option in the future for PHP to generate a = warning when this type of comment is missing? Key to this request is = that PHP also generates a warning when warnings are turned on during = development. Also, when reading code I tend to have "comment blindness" similar to = how people have "ad blindness" when browsing the web. Since comments are = typically not code and are often not maintained I don't trust them so = only read comments when the code is hard to decipher. In this case if I = saw a missing break I would assume the person intended it and might not = realize there is a comment indicating it. But YMMV. =20 > a token that would effectively no-op in all circumstances. Is it really a no-op? I envisioned is a jump to the next case. But I also saw that it was small enough scope I could probably use it to = learn how to author a patch for PHP. BTW, GoLang has exactly what I am asking about:=20 https://github.com/golang/go/wiki/Switch#fall-through -Mike > On Oct 17, 2019, at 5:42 PM, Mark Randall wrote: >=20 > On 17/10/2019 21:54, Mike Schinkel wrote: >> 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 = warnings must come with to future plans to generate errors I would = personally be 100% okay if it indefinitely generated only a warning. >=20 > Would you put this at switch level, or case level? >=20 > Unless your plan is to redefine how switch works by default, which = would be quite ambitious, I'm not sure it makes a great deal of sense to = add a token that would effectively no-op in all circumstances. >=20 > It sounds like a job for a static analysis comment: >=20 > /** @DisableSwitchStatementFallthroughWarning */ > switch ($x) { > case 1: > $x =3D doSomething(); >=20 > case 2: > doLaLaLaLa(); > break; >=20 > default: > doTralala(); > } >=20 > -- > Mark Randall >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 --Apple-Mail=_A941E84F-90FB-476F-ACE2-5C6ED6D62B30--