php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49993 switch: default is triggering every time
Submitted: 2009-10-25 23:33 UTC Modified: 2009-10-26 00:31 UTC
From: sworddragon2 at aol dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0 OS: Windows XP Professional SP3
Private report: No CVE-ID: None
 [2009-10-25 23:33 UTC] sworddragon2 at aol dot com
Description:
------------
In this example default is triggering although the case statement is triggering before.

Reproduce code:
---------------
switch(1)
{
	case 1: echo "case 1: triggered\n";
	default: echo 'default: triggered';
}

Expected result:
----------------
case 1: triggered

Actual result:
--------------
case 1: triggered
default: triggered

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-25 23:35 UTC] rasmus@php.net
Please read the documentation on switch/case (for any language) carefully.  This is expected behaviour.  Hint, read about "break".
 [2009-10-26 00:27 UTC] sworddragon2 at aol dot com
I have allready read the documentation. Maybe it's a misunderstanding because the switch documentation isn't translated in my language but the documentation says the following:

A special case is the default case. This case matches anything that wasn't matched by the other cases. For example: 


If this issue is working correctly the documentation is wrong i think.
 [2009-10-26 00:31 UTC] sean@php.net
Hint: read what Rasmus wrote about "hint."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jun 24 07:01:33 2025 UTC