Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76487 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47711 invoked from network); 13 Aug 2014 14:38:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Aug 2014 14:38:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.173 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.216.173 mail-qc0-f173.google.com Received: from [209.85.216.173] ([209.85.216.173:46688] helo=mail-qc0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/A6-11625-4787BE35 for ; Wed, 13 Aug 2014 10:38:45 -0400 Received: by mail-qc0-f173.google.com with SMTP id w7so4155415qcr.18 for ; Wed, 13 Aug 2014 07:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=zBH1np07FP+SsYHYBwu4xHBaC4XYGwPbtYBIRgkPDCw=; b=KS1iehkVaM8Jv5Bf8WOl2Tu7jIWoDFp+h2D2fKHhHwqaQdco+FcDZpM+9Wo96yFe2P uPRR5N3QgZcubcPWaRrnk5u97MZ0+xlI2VNI/Qh6Y2hSusc4aKeUwemtlsoaq5inKXyM o0ULmWDp2hTYdEkE8524mCHYsPSOoDmapgqatQ1WBrUOoZ/73Nq4kwL5SGtORHblwSHr D+gbxgFpcepc+AsnI1zQT9pn73Kl+8oqu4IrGAFKOdjcInqBL3NOR6wqj682ag1K8sIw ramBapFoQIwPLnIcu8mVWXB7DXPz0J8h9oc8Gtadck/tdgTrZ1wHlDfVHq7V5EZsK9Cr FPsA== MIME-Version: 1.0 X-Received: by 10.229.232.1 with SMTP id js1mr7665914qcb.20.1407940721543; Wed, 13 Aug 2014 07:38:41 -0700 (PDT) Received: by 10.140.102.111 with HTTP; Wed, 13 Aug 2014 07:38:41 -0700 (PDT) In-Reply-To: <53EB6E69.7080205@gmail.com> References: <942D2AF6-BDC2-4214-BD58-4B5945C28CE3@ajf.me> <53EB5F8E.5050607@gmail.com> <53EB6E69.7080205@gmail.com> Date: Wed, 13 Aug 2014 16:38:41 +0200 Message-ID: To: Rowan Collins Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11343e1e929151050083bec4 Subject: Re: [PHP-DEV] [RFC] Disallow multiple default blocks in a single switch statement From: tyra3l@gmail.com (Ferenc Kovacs) --001a11343e1e929151050083bec4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Aug 13, 2014 at 3:55 PM, Rowan Collins wrote: > Ferenc Kovacs wrote (on 13/08/2014): > >> I think you misunderstood that part, I was thinking about a state machin= e >> like this: >> >> 1. function doStuff(){ >> 2. switch($state){ >> 3. case OPENDOOR: >> 4. if(!opendoor()){ >> 5. break; >> 6. } >> 7. $state =3D SITDOWN; >> 8. case SITDOWN: >> 9. if(!sitdown()){ >> 10. break; >> 11. } >> 12. $state =3D SIPWHISKEY; >> 13. case SIPWHISKEY: >> 14. sipwhiskey(); >> 15. } >> 16. } >> >> >> >> where you modify the switch variable in one case and fall through into >> another. >> as I mentioned I don't have a reasonable use-case for multiple defaults, >> but I can see some for multiple case labels in general, and I don't thin= k >> that it is better to have different behavior for case and default in thi= s >> regard. >> > > > The assignments to $state in that code do not make any difference to > execution, control simply flows forwards whenever there is no "break". > > $state is only tested once, to select the initial label to jump to, so no > amount of reassigning it, or adding duplicate labels, can ever cause a > second jump. > > I'm tempted to write a PHP script that emulates the switch execution by > building a set of if and goto statements, which might make some of this > behaviour clearer (not just for this discussion, but for other confusion > I've seen elsewhere), but I don't have time right now. > yeah, and that is a documented behavior, I've just had a momentary brain-fart here (which is funny considering that at one point I even wrote a codesniffer rule for generating warnings for fall-through case statements without an explicit comment). thanks again for pointing that out. and sorry for the noise. ps: I still hold onto my no vote, even thought it is a small BC break, it is still a BC break, I wouldn't consider the current patch as a bugfix(and even thought that the spec documented this as not a valid syntax hhvm still supported it, ableit picking the first default when there are more than one) , I would prefer having it E_DEPRECATED first in 5.next and we can remove it in 7.0. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --001a11343e1e929151050083bec4--