Menu

← Back to doWhile.*

Error Identifier: doWhile.alwaysFalse

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
{
	do {
		echo 'hello';
	} while (false);
}

Why is it reported? #

The condition in the do-while loop always evaluates to false, meaning the loop body will always execute exactly once. While do { ... } while (false); is a valid pattern in some contexts, it may indicate a logic error when the condition was intended to be dynamic.

How to fix it #

If the loop body should only execute once, remove the loop:

 <?php declare(strict_types = 1);
 
 function doFoo(): void
 {
-	do {
-		echo 'hello';
-	} while (false);
+	echo 'hello';
 }

Or fix the condition so it depends on a meaningful expression.

How to ignore this error #

You can use the identifier doWhile.alwaysFalse to ignore this error using a comment:

// @phpstan-ignore doWhile.alwaysFalse
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: doWhile.alwaysFalse

Rules that report this error #

  • PHPStan\Rules\Comparison\DoWhileLoopConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.