|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30285 switch statement: default executed when case matches
Submitted: 2004-09-30 05:25 UTC Modified: 2004-10-13 03:50 UTC
Avg. Score:4.4 ± 1.4
Reproduced:29 of 43 (67.4%)
Same Version:20 (69.0%)
Same OS:14 (48.3%)
From: benjcarson at digitaljunkies dot ca Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2004-09-30 (dev) OS: Debian Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
12 - 6 = ?
Subscribe to this entry?

 [2004-09-30 05:25 UTC] benjcarson at digitaljunkies dot ca
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 ( 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:
$x = "a";
switch ($x) {
    echo "default\n";
  case "a":
    echo "case: a\n";

Expected result:
case: a

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-08 16:25 UTC] Jared dot Williams1 at ntlworld dot com
5.0.2 does produce the expected result, as does 4.3.8
 [2004-10-08 22:49 UTC] paco at arsteca dot net
got expected result with 4.3.2, including CLI
 [2004-10-13 03:34 UTC] dev at null dot dk
got expected result in php version 4.3.1 running under apache.
 [2004-10-13 03:50 UTC] benjcarson at digitaljunkies dot ca
As per discussion on, this has been fixed in CVS (5.1.x-dev).  Thanks Andi.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 17 20:03:37 2021 UTC