Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76486 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44258 invoked from network); 13 Aug 2014 13:56:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Aug 2014 13:56:00 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.175 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.175 mail-we0-f175.google.com Received: from [74.125.82.175] ([74.125.82.175:35840] helo=mail-we0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 20/26-11625-D6E6BE35 for ; Wed, 13 Aug 2014 09:55:59 -0400 Received: by mail-we0-f175.google.com with SMTP id t60so11121141wes.6 for ; Wed, 13 Aug 2014 06:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=Pz11s+E2FpizwwMW3cpwx9WniUBTxmis5DhmbuY8T1Q=; b=j0P6HHdFpGuS9MBpvn6/bluUHZ8ZNQScuVupahZ9Gm2a2mRl8ttfW61uqgmBj/mmR+ V6dF1cnk9oDql40sX9TVq1pmQZYGBnhrsxv5r+MVaaAq2a1MIBOVVpS+UONjbW8EUjZO ZJ7Z1FES9PxkiHmbmaVOOvrCt0PDxrMwaJY0emMhiwpPGOj3dvbiz4ols9MDGk7NJ0hF g0Re1tHVcSnRM3M6LDFL3NnDbfbtZz7ObSzfk/AHsnKw5nePK4Xw8HVncKTRgvYnrCcd zhObH2UAdZ3rXS5E0mf7nj76iyAMo48kFSvwzE97AT0LWXcaBA4pCD4sMNV415VkIl3L dULg== X-Received: by 10.194.6.101 with SMTP id z5mr4679806wjz.79.1407938154775; Wed, 13 Aug 2014 06:55:54 -0700 (PDT) Received: from [192.168.0.177] ([62.189.198.114]) by mx.google.com with ESMTPSA id ko8sm4608462wjc.11.2014.08.13.06.55.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Aug 2014 06:55:54 -0700 (PDT) Message-ID: <53EB6E69.7080205@gmail.com> Date: Wed, 13 Aug 2014 14:55:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: PHP Internals References: <942D2AF6-BDC2-4214-BD58-4B5945C28CE3@ajf.me> <53EB5F8E.5050607@gmail.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------050701090100050600030108" Subject: Re: [PHP-DEV] [RFC] Disallow multiple default blocks in a single switch statement From: rowan.collins@gmail.com (Rowan Collins) --------------050701090100050600030108 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Ferenc Kovacs wrote (on 13/08/2014): > I think you misunderstood that part, I was thinking about a state > machine like this: > > 1. function doStuff(){ > 2. switch($state){ > 3. case OPENDOOR: > 4. if(!opendoor()){ > 5. break; > 6. } > 7. $state = SITDOWN; > 8. case SITDOWN: > 9. if(!sitdown()){ > 10. break; > 11. } > 12. $state = 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 think that it is better to have different behavior for case > and default in this 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. --------------050701090100050600030108--