#30285 [Com]: switch statement: default executed when case matches
| From: | paco at arsteca dot net | Date: | Fri, 08 Oct 2004 20:49:10 +0000 |
| Subject: | #30285 [Com]: switch statement: default executed when case matches | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-67322@lists.php.net to get a copy of this message | ||
ID: 30285
Comment by: paco at arsteca dot net
Reported By: benjcarson at digitaljunkies dot ca
Status: Open
Bug Type: Zend Engine 2 problem
Operating System: Debian Linux
PHP Version: 5CVS-2004-09-30 (dev)
New Comment:
got expected result with 4.3.2, including CLI
Previous Comments:
------------------------------------------------------------------------
[2004-10-08 16:25:50] Jared dot Williams1 at ntlworld dot com
5.0.2 does produce the expected result, as does 4.3.8
------------------------------------------------------------------------
[2004-09-30 05:25:18] benjcarson at digitaljunkies dot ca
Description:
------------
It seems that the default: block of a switch statement now
short-circuits the remaining case: tests. If the default: block is put
before a matching case: block, it will _always_ be executed. While the
docs (http://www.php.net/manual/en/control-structures.switch.php) do
recommend making default: last, this is a BC break (tested with 5.0.0
and 4.3.2).
This bug is also present at least as early as the 5.1.x-dev 2004-09-25
snap (sorry, the next earliest one I have is 5.0.0).
The reproduce code below works if the default: block is put after the
case "a": block.
Reproduce code:
---------------
<?php
$x = "a";
switch ($x) {
default:
echo "default\n";
break;
case "a":
echo "case: a\n";
break;
}
?>
Expected result:
----------------
case: a
Actual result:
--------------
default
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30285&edit=1