Skip to content

UnusedGotoLabel ​

info on by default quick-fix

Group: Unused · PhpStorm name: UnusedGotoLabelInspection

A goto label that no goto statement targets is dead code; it only suggests control flow that does not exist. Remove it.

Example ​

php
<?php
function retry_job($job)
{
    $attempts = 0;
    again:
    done:
    Again:
    if (!$job->run() && ++$attempts < 3) {
        goto again;
    }

    $cleanup = function () {
        finish:
        return true;
        goto finish;
    };
}

start:
echo "top level";
php
<?php
function retry_job($job)
{
    $attempts = 0;
    again:
    if (!$job->run() && ++$attempts < 3) {
        goto again;
    }

    $cleanup = function () {
        finish:
        return true;
        goto finish;
    };
}

start:
echo "top level";

Reported:

  • line 6: Label 'done' is never targeted by a goto; remove it.
  • line 7: Label 'Again' is never targeted by a goto; remove it.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore UnusedGotoLabel

/**
 * @noinspection UnusedGotoLabelInspection
 */

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