Bug #67757 [Opn->Wfx]: multiple default cases

From: Date: Fri, 09 Jan 2015 15:15:28 +0000
Subject: Bug #67757 [Opn->Wfx]: multiple default cases
References: 1  Groups: php.standards 
Request: Send a blank email to standards-+get-696@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67757&edit=1 ID: 67757 Updated by: jpauli@php.net Reported by: php at tutteli dot ch Summary: multiple default cases -Status: Open +Status: Wont fix Type: Bug Package: PHP Language Specification PHP Version: 5.5.15 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php I close with won't fix, as we now have an RFC for this case, and a PR as well Previous Comments: ------------------------------------------------------------------------ [2014-08-13 13:51:50] tyrael@php.net nevermind me, I'm just an idiot. /o\ ------------------------------------------------------------------------ [2014-08-13 11:32:38] tyrael@php.net I would argue, that the correct output should be 1. If you replace default with case 1, that is what the output will be, as both of the cases would match in the order of definition, but after the first case we would break out so the second case would never got a chance to be executed. What's even more interesting is that even the default blocks work this way if there is a normal case block which matches the value in the switch. here is an example for the original snippet from the bugreport: http://3v4l.org/9RtL8 here is one for the same but using matching case vs default: http://3v4l.org/Ioqsq and here is an example where the defaults behave differently if there is a previous matching case: http://3v4l.org/r3poR so I think that the hhvm behavior is correct and the current php behavior is wrong, but this isn't a design problem of the support of multiple defaults but an implementation problem, where we don't properly iterate over the cases from top to bottom. ------------------------------------------------------------------------ [2014-08-06 04:43:44] pollita@php.net https://wiki.php.net/rfc/switch.default.multiple ------------------------------------------------------------------------ [2014-08-05 23:32:15] joelm@php.net +1 on the spec being the optimal behavior. Don't allow this. PHP5 and HHVM actually differ on behavior here, scarily enough. PHP5 executes the code in the last default. HHVM executes the code in the first default. ------------------------------------------------------------------------ [2014-08-05 23:21:00] ajf@php.net FWIW, I'm also in favour of fixing implementations here. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=67757 -- Edit this bug report at https://bugs.php.net/bug.php?id=67757&edit=1

« previous php.standards (#696) next »