Opened 8 years ago

Closed 7 years ago

Last modified 43 years ago

#382 closed Bugs (Fixed)

Error with switch when last case block omits break or return

Reported by: rbarreca Owned by: nobody
Priority: 5 Milestone:
Component: PHP Parser Version: None
Keywords: Cc:

Description

Code like this gives an error and screws up the parsing
on the rest of the page.  Says Parser error "Error in
expression (found token '}')."  Then the rest of the
page has parse errors.  Using ver 1.1.8.CVS-20051108.


switch ($replace) {
        case FILE_EXISTS_RENAME:
          // Destination file already exists and we
can't replace is so we try and
          // and find a new filename.
          if ($pos = strrpos($basename, '.')) {
            $name = substr($basename, 0, $pos);
            $ext = substr($basename, $pos);
          }
          else {
            $name = $basename;
          }

          $counter = 0;
          do {
            $dest = $directory .'/'. $name .'_'.
$counter++ . $ext;
          } while (file_exists($dest));
          break;

        case FILE_EXISTS_ERROR:
          drupal_set_message(t('File copy failed. File
already exists.'), 'error');
          return 0;

        case FILE_EXISTS_REPLACE:
          // Leave $dest where it is for replace.
      }

Change History (4)

comment:1 Changed 8 years ago by bananeweizen

Logged In: YES 
user_id=440739

To my mind this is no bug. Every label statement requires a
compound statement, so you need to have at least a semicolon
in your last case statement. I checked that with a BNF of PHP4.
The interesting thing is that PHP doesn't give any warning
for this.

comment:2 Changed 8 years ago by axelcl

Logged In: YES 
user_id=1143825

Fixed with CVS-20051219
The "default:" branch is currently handled the same way.
Please close if Ok.

comment:3 Changed 7 years ago by bananeweizen

Logged In: YES 
user_id=440739

Works fine for me with current CVS. Set to pending.

comment:4 Changed 7 years ago by sf-robot

  • Status changed from assigned to closed
Logged In: YES 
user_id=1312539

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Note: See TracTickets for help on using tickets.