Menu

Error Identifier: label.unused

← Back to label.*

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

function doFoo(): void
{
	unused:
	echo 'hello';
}

Why is it reported? #

The label unused is defined but there is no goto statement that references it. Labels only have meaning as targets for goto statements. An unreferenced label is dead code that likely indicates leftover code from refactoring or a missing goto statement.

A label is also considered unused when its corresponding goto statement is in a different scope. Labels defined in an outer function are not reachable from closures, anonymous classes, or nested functions.

How to fix it #

Remove the unused label:

 function doFoo(): void
 {
-	unused:
 	echo 'hello';
 }

Or add the corresponding goto statement if the label was intended to be used:

 function doFoo(): void
 {
+	if (rand(0, 1) === 0) {
+		goto end;
+	}
+	echo 'hello';
-	unused:
-	echo 'hello';
+	end:
+	echo 'done';
 }

How to ignore this error #

You can use the identifier label.unused to ignore this error using a comment:

// @phpstan-ignore label.unused
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: label.unused

Rules that report this error #

  • PHPStan\Rules\Keywords\UnusedLabelRule [1]
Theme
A
© 2026 PHPStan s.r.o.