php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8114 case can be terminated by ; as well as : when writing switch statements.
Submitted: 2000-12-05 05:52 UTC Modified: 2000-12-12 06:20 UTC
From: juhl at eisenstein dot dk Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.3pl1 OS: Linux
Private report: No CVE-ID: None
 [2000-12-05 05:52 UTC] juhl at eisenstein dot dk
When writing switch statements the documentation specifies that the different case statements should be terminated by : (colon), but a ; (semicolon) is also accepted. 

The code below writes 'Hello world' to the client. I believe it should instead have produced a parse error on the 

case 'bar'; 

line.


$foo = "bar";
switch ($foo) {
  case 'bar';
    echo 'Hello world\n';
    break;
  default:
    echo 'Hit the default\n';
    break;
}


Best regards,
Jesper Juhl
juhl@eisenstein.dk

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-12 06:20 UTC] stas@php.net
From what I see, this is intended behaviour. I guess that's
because of "alternative syntax" (PHP/FI remanant) support.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 21:00:01 2026 UTC