Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76480 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31776 invoked from network); 13 Aug 2014 12:51:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Aug 2014 12:51:52 -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.48 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wg0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:48847] helo=mail-wg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/A3-11625-66F5BE35 for ; Wed, 13 Aug 2014 08:51:50 -0400 Received: by mail-wg0-f48.google.com with SMTP id x13so11160359wgg.19 for ; Wed, 13 Aug 2014 05:52:31 -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:content-transfer-encoding; bh=fW3MHtc5NLxHjOk8TKMiLQa/LGwVeSjxuXhcVH+SFsE=; b=XW1fP1bdg47uwEl5q/EBQCwk0Y0a892Sg1nyRCuEesp0zpEHuzPUA28SOQApX3FACE 7/CaC6xukdafDgiLfSMkMwG6NxUGzhV15V5vjwsWKnYPmgbYJU5xpg71OzATP4MSpiFN URUz7tNRWJdNcS1GmADH2OJd4SAyNH4VZF8Q3wLwsxnHFZO95km+bMU8U+Gb9ZVDtd17 KfH5ckq0GmMwKgyDA5coeUo+67pXrz+VyOuF/slwznEj+9Po2XIcGBrhUg2N2sS0ycnF xRSJ9XslpRd2IccghQGAisp6mu0rhkOu4C5SIxtt9tqf/28fwaLuZlFEAjWSNsvP2jmM KjHA== X-Received: by 10.194.58.83 with SMTP id o19mr4526856wjq.20.1407934351099; Wed, 13 Aug 2014 05:52:31 -0700 (PDT) Received: from [192.168.0.177] ([62.189.198.114]) by mx.google.com with ESMTPSA id c8sm4269773wjw.6.2014.08.13.05.52.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Aug 2014 05:52:30 -0700 (PDT) Message-ID: <53EB5F8E.5050607@gmail.com> Date: Wed, 13 Aug 2014 13:52:30 +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: internals@lists.php.net References: <942D2AF6-BDC2-4214-BD58-4B5945C28CE3@ajf.me> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Disallow multiple default blocks in a single switch statement From: rowan.collins@gmail.com (Rowan Collins) Ferenc Kovacs wrote (on 13/08/2014): > not sure what do you mean here, multiple default cases can be reached the > same way as any other duplicated case branch(as shown in my snippet in the > mail you replied to). If you're talking about http://3v4l.org/eZdPU then those duplicates are definitely being silently ignored. Remember that the switch statement is just a glorified goto, so execution starts at the first matching case and then carries on until you hit a "break" or the end of the switch block. In that example, it finds the first "case 'foo':", does a goto, and at that point all the other labels are completely irrelevant; the 4 echo statements are executed in order as though the other labels didn't exist. If you feed it something other than 'foo', then the behaviour being discussed kicks in: for whatever reason, the *last* default label is selected as the target of the goto, so only the last echo is executed: http://3v4l.org/TfYiQ Interestingly, HHVM apparently behaves the same on that example, although others mentioned it selecting the first rather than last default label. > not sure about the multiple defaults, but I'm fairly sure that there are > code out there which uses switch blocks as state-machines, and changes the > switch variable in the case blocks, and have duplicated case blocks for > executing code after the switch variable reached it's final form. Multiple cases do not make any difference here; the label to jump to is selected only once, so if you want to change the state and jump to a different label, you have to wrap the switch in a loop, and evaluate it again. If you specify multiple labels matching the same state, the second one can never be reached. http://3v4l.org/i3746 -- Rowan Collins [IMSoP]