Skip to content

SuspiciousSemicolon ​

error on by default

Group: Probable bugs · PhpStorm name: SuspiciousSemicolonInspection

A lone ; used as the body of an if/elseif/else or of a loop makes that body empty; the block that follows then runs unconditionally (or only once, after the loop). This is nearly always an accidental semicolon.

Example ​

php
<?php
function poll($queue, $ready, $late) {
    if ($ready) ;
    elseif ($late) ;
    else ;
    {
        notify();
    }

    while ($queue->next()) ;
    do ; while ($queue->busy());
    for ($i = 3; $i > 0; $i--) ;
    foreach ($queue as $job) ;
    if ($late) { ; }
    declare(ticks=1);
    notify();;
}

Reported:

  • line 3: This ';' is the entire body of the statement; probably unintended.
  • line 4: This ';' is the entire body of the statement; probably unintended.
  • line 5: This ';' is the entire body of the statement; probably unintended.
  • line 10: This ';' is the entire body of the statement; probably unintended.
  • line 11: This ';' is the entire body of the statement; probably unintended.
  • line 12: This ';' is the entire body of the statement; probably unintended.
  • line 13: This ';' is the entire body of the statement; probably unintended.

Configure ​

In custos.json:

json
{
  "rules": {
    "SuspiciousSemicolon": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file), either of:

php
// @custos-ignore SuspiciousSemicolon

/**
 * @noinspection SuspiciousSemicolonInspection
 */

Released under the MIT License. Rule catalogue modelled on Php Inspections (EA Extended); independent clean-room implementation.