Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76378 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46257 invoked from network); 6 Aug 2014 12:43:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Aug 2014 12:43:49 -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.46 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.46 mail-wg0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:63609] helo=mail-wg0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/F4-13038-40322E35 for ; Wed, 06 Aug 2014 08:43:48 -0400 Received: by mail-wg0-f46.google.com with SMTP id m15so2540569wgh.29 for ; Wed, 06 Aug 2014 05:44:15 -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=AREabH8OPTNLQwgMnlbA0CGwv5uDwxUOikzNdOfrNiE=; b=zpI6F2kmJcNfDs8wpTPctxZt/6v9e5pFuhV360FVMJKYxoQKt2wvX45tzbVRgpgR9r ulh4GeJUXVxDszOL/caGtpLhhMHsQbMu7JiPPaqYOfgAKAsCinmN1LRAYpp5mkG9i+Po /89l+SfCz3RNyFw9FnAhRpidDguybCtdLdR40bEh9keX7IDdBEGkN1ttDBuck2XKc6dz 0nX4sKRA5YCOEUchrFeGGL1X0UKwCaIwwIXRBroJ9nCNhB7Jql/If9JskUx/FO7ka8hK j43u/wgrHDPMzwR3hayuwi+msVgy17m6TCrgrmDOklKTPy36pEw5U80MHoNAzY5dxCPP yoeg== X-Received: by 10.194.23.135 with SMTP id m7mr15726409wjf.2.1407329054893; Wed, 06 Aug 2014 05:44:14 -0700 (PDT) Received: from [192.168.0.177] ([62.189.198.114]) by mx.google.com with ESMTPSA id ez1sm5852622wib.15.2014.08.06.05.44.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Aug 2014 05:44:14 -0700 (PDT) Message-ID: <53E22230.2010304@gmail.com> Date: Wed, 06 Aug 2014 13:40:16 +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: <53E2006E.6080809@gmail.com> <53E218C6.20703@lsces.co.uk> In-Reply-To: <53E218C6.20703@lsces.co.uk> 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) Lester Caine wrote (on 06/08/2014): > On 06/08/14 11:16, Rowan Collins wrote: >> According to the bug report, HHVM also accepts multiple default blocks, >> but uses the first rather than the last. It's probably not worth >> implementing specific code there to take the last default label just in >> order to adhere to a 5.6 spec, but is worth making it detect multiple >> labels to bring it in line with the proposed change. >> >> So either we declare the php.net implementation to be in violation of >> the spec (which isn't completely insane - the spec shouldn't mirror >> behaviour to the point of incorporating the entire bug list); or we >> document the php.net behaviour as "correct", but accept that nobody is >> going to implement that part of the spec as written, and fix it in the >> next release of both the implementation and the spec. > It is perhaps interesting that this problem has not turned up before? As > I indicated in another thread I was surprised to see 'default' as the > first item in an example. I'm sure I'm not alone in always putting it at > the end, and I quite often will have a previous block which does not > have a 'break' so that the default element is added to other actions on > some keys for that reason. How much of the core PHP is still 'normal > practice' rather than 'by design' :) > You could equally have the default case run some extra logic *before* one of the steps, since it doesn't have to be last. The goto-like behaviour of case and default labels originates in C, which makes this answer on SO worth mentioning: http://stackoverflow.com/a/3110478/157957 The reason some languages require default to be the last label is presumably that they treat it as equivalent to a case statement that always matches, and so never test lower labels. "Normal practice" is often stricter than what is technically possible in a language, because it is aimed at writing readable and maintainable code. Which in turn has no bearing on the ability to specify multiple defaults (which never makes sense, except as a result of a lazy code generator). -- Rowan Collins [IMSoP]