php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64594 case without default should be failed
Submitted: 2013-04-05 20:18 UTC Modified: 2013-04-05 23:22 UTC
From: vdeepakkumar at msn dot com Assigned:
Status: Not a bug Package: *Compile Issues
PHP Version: 5.4.13 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vdeepakkumar at msn dot com
New email:
PHP Version: OS:

 

 [2013-04-05 20:18 UTC] vdeepakkumar at msn dot com
Description:
------------
When we have switch case statements and when case statements are skipped of break 
statement inadvertantly the page/control would fail. Similar to C#, php compiler 
should throw an error 'Control can not fall through case constructs'.


Test script:
---------------
switch ($t)
{
    case "t":
           echo "test";
    case "e":
           echo "e test";
}

Expected result:
----------------
It should fail with parse error and the user correction should be 

switch ($t)
{
    case "t":
           echo "test";
           break;
    case "e":
           echo "e test";
           break;
}

Actual result:
--------------
It should fail with parse error and the user correction should be 

switch ($t)
{
    case "t":
           echo "test";
           break;
    case "e":
           echo "e test";
           break;
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-05 20:52 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-04-05 20:52 UTC] nikic@php.net
No way this is going to happen. PHP's switch allows fall-through and intentionally so. Same way it works in nearly any other language implementing switch.
 [2013-04-05 21:05 UTC] vdeepakkumar at msn dot com
Actually C# compiler checks such anomalies.

Control cannot fall through from one case label ('case <title>:') to another. 
Check out an example http://stackoverflow.com/questions/6696692/control-cannot-
fall-through-from-one-case-label
 [2013-04-05 23:22 UTC] rasmus@php.net
Maybe, but C-derived languages do not and there is tons of code out there that 
specifically relies on this feature. I have written a bunch myself. This will 
never change.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Feb 25 06:01:25 2020 UTC