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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC